Skip to content

Commit bbaec3d

Browse files
committed
[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.
1 parent 318297c commit bbaec3d

File tree

1 file changed

+19
-3
lines changed

1 file changed

+19
-3
lines changed

stdlib/public/Darwin/Foundation/NSError.swift

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

409+
public func hash(into hasher: inout Hasher) {
410+
hasher.combine(_code)
411+
}
412+
409413
public var hashValue: Int { return _code }
414+
415+
public func _rawHashValue(seed: Int) -> Int {
416+
return _code._rawHashValue(seed: seed)
417+
}
410418
}
411419

412420
/// Describes a bridged error that stores the underlying NSError, so
@@ -480,9 +488,17 @@ public extension _BridgedStoredNSError {
480488
}
481489

482490
/// Implementation of Hashable for all _BridgedStoredNSErrors.
483-
public extension _BridgedStoredNSError {
484-
var hashValue: Int {
485-
return _nsError.hashValue
491+
extension _BridgedStoredNSError {
492+
public func hash(into hasher: inout Hasher) {
493+
hasher.combine(_nsError)
494+
}
495+
496+
public var hashValue: Int {
497+
return _nsError.hash
498+
}
499+
500+
public func _rawHashValue(seed: Int) -> Int {
501+
return _nsError._rawHashValue(seed: seed)
486502
}
487503
}
488504

0 commit comments

Comments
 (0)