Skip to content

Commit 6c5a6a6

Browse files
committed
[stdlib] Make sure _SwiftNewtypeWrapper hashes the same way as its RawValue
_SwiftNewtypeWrapper forwarded hashValue to its rawValue, but it failed to do the same for _hash(into:), which resulted in the wrapper struct having subtly different hashing than the raw value. This violated an implicit invariant when dictionaries/sets of such types were bridged to Objective-C through AnyHashable, leading to nondeterministic but frequent crashes. rdar://problem/39398060
1 parent 5c7f211 commit 6c5a6a6

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

stdlib/public/core/NewtypeWrapper.swift

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,16 @@
1515
/// attribute.
1616
public protocol _SwiftNewtypeWrapper : RawRepresentable { }
1717

18-
extension _SwiftNewtypeWrapper where Self.RawValue : Hashable {
18+
extension _SwiftNewtypeWrapper where Self: Hashable, Self.RawValue : Hashable {
1919
@inlinable // FIXME(sil-serialize-all)
2020
public var hashValue: Int {
2121
return rawValue.hashValue
2222
}
23+
24+
@inlinable // FIXME(sil-serialize-all)
25+
public func _hash(into hasher: inout _Hasher) {
26+
hasher.append(rawValue)
27+
}
2328
}
2429

2530
#if _runtime(_ObjC)

0 commit comments

Comments
 (0)