Skip to content

Commit 20e826a

Browse files
fix hashable
1 parent 0efca8b commit 20e826a

File tree

2 files changed

+5
-5
lines changed

2 files changed

+5
-5
lines changed

CodeGeneratorTests/GeneratedHash.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@ extension EquatableClazz: Hashable {
66

77
var hashValue: Int {
88
var hashValue = 1
9-
let hashableVars: [Hashable?] = [var0, var1, var2]
9+
let hashableVars: [AnyHashable?] = [var0, var1, var2]
1010
hashableVars.forEach {
11-
hashValue = 31 * hashValue + $0?.hashValue ?? 0
11+
hashValue = 31 * hashValue + ($0?.hashValue ?? 0)
1212
}
1313
return hashValue
1414
}

Generate.../HashableGenerator.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,11 +47,11 @@ struct HashableGenerator: Generator {
4747
lines.append("\(indentation)var hashValue: Int {")
4848
lines.append("\(indentation)\(indentation)var hashValue = 1")
4949
let hashableVars = varSignatures.map { $0.name }.joined(separator: ", ")
50-
var varsType = "[Hashable]"
50+
var varsType = "[AnyHashable]"
5151
var varHash = "$0.hashValue"
5252
if (varSignatures.filter { $0.type.isOptional }).count > 0 {
53-
varsType = "[Hashable?]"
54-
varHash = "$0?.hashValue ?? 0"
53+
varsType = "[AnyHashable?]"
54+
varHash = "($0?.hashValue ?? 0)"
5555
}
5656
lines.append("\(indentation)\(indentation)let hashableVars: \(varsType) = [\(hashableVars)]")
5757

0 commit comments

Comments
 (0)