Skip to content

Commit e5f1450

Browse files
lorenteyairspeedswift
authored andcommitted
[5.0][Foundation] Update hashing for bridged NSError protocols (#21205)
* [Foundation] Update hashing for bridged Error/NSError types Protocols in resilient libraries that wish to provide a default implementation of hashing need to do so by providing a hash(into:) implementation. hashValue has been deprecated as a Hashable requirement in SE-0206. Implementing only it in a protocol extension curses conforming types to get deprecation warnings by default. (cherry picked from commit bbaec3d) * [Foundation] _Bridged[Stored]NSError: Remove explicit impls for hashValue/_rawHashValue The compiler-synthesized / stdlib-provided default implementations seem perfectly fine for these. (cherry picked from commit 21d31ea) * [Foundation] CocoaError.Code, URLError.Code: Remove hashValue implementation These implementations did not produce the same hash values as the raw value. RawRepresentable provides a correct hashing implementation by default, so let’s just use that. (cherry picked from commit 23188af)
1 parent 3d7d3bd commit e5f1450

File tree

1 file changed

+6
-12
lines changed

1 file changed

+6
-12
lines changed

stdlib/public/SDK/Foundation/NSError.swift

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -406,7 +406,9 @@ extension _BridgedNSError where Self.RawValue: FixedWidthInteger {
406406
self.init(rawValue: RawValue(_bridgedNSError.code))
407407
}
408408

409-
public var hashValue: Int { return _code }
409+
public func hash(into hasher: inout Hasher) {
410+
hasher.combine(_code)
411+
}
410412
}
411413

412414
/// Describes a bridged error that stores the underlying NSError, so
@@ -480,9 +482,9 @@ public extension _BridgedStoredNSError {
480482
}
481483

482484
/// Implementation of Hashable for all _BridgedStoredNSErrors.
483-
public extension _BridgedStoredNSError {
484-
var hashValue: Int {
485-
return _nsError.hashValue
485+
extension _BridgedStoredNSError {
486+
public func hash(into hasher: inout Hasher) {
487+
hasher.combine(_nsError)
486488
}
487489
}
488490

@@ -568,10 +570,6 @@ public struct CocoaError : _BridgedStoredNSError {
568570
public init(rawValue: Int) {
569571
self.rawValue = rawValue
570572
}
571-
572-
public var hashValue: Int {
573-
return self.rawValue
574-
}
575573
}
576574
}
577575

@@ -1799,10 +1797,6 @@ public struct URLError : _BridgedStoredNSError {
17991797
public init(rawValue: Int) {
18001798
self.rawValue = rawValue
18011799
}
1802-
1803-
public var hashValue: Int {
1804-
return self.rawValue
1805-
}
18061800
}
18071801
}
18081802

0 commit comments

Comments
 (0)