Skip to content

Commit 9b6e39e

Browse files
committed
[SE-0112] Generalize _BridgedStoredNSError for all integer types.
This will get clearer when SE-0104 gets implemented and we can use the Integer protocol.
1 parent 9522d99 commit 9b6e39e

File tree

1 file changed

+21
-5
lines changed

1 file changed

+21
-5
lines changed

stdlib/public/SDK/Foundation/NSError.swift

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -344,18 +344,34 @@ public protocol _BridgedStoredNSError :
344344

345345
/// Various helper implementations for _BridgedStoredNSError
346346
public extension _BridgedStoredNSError
347-
where Code: RawRepresentable, Code.RawValue == Int {
348-
// FIXME: Generalize based on the Integer protocol once SE-0104 is
349-
// implemented.
347+
where Code: RawRepresentable, Code.RawValue: SignedInteger {
348+
// FIXME: Generalize to Integer.
350349
public var code: Code {
351-
return Code(rawValue: _nsError.code)!
350+
return Code(rawValue: numericCast(_nsError.code))!
352351
}
353352

354353
/// Initialize an error within this domain with the given ``code``
355354
/// and ``userInfo``.
356355
public init(_ code: Code, userInfo: [String : AnyObject] = [:]) {
357356
self.init(_nsError: NSError(domain: Self._nsErrorDomain,
358-
code: code.rawValue,
357+
code: numericCast(code.rawValue),
358+
userInfo: userInfo))
359+
}
360+
}
361+
362+
/// Various helper implementations for _BridgedStoredNSError
363+
public extension _BridgedStoredNSError
364+
where Code: RawRepresentable, Code.RawValue: UnsignedInteger {
365+
// FIXME: Generalize to Integer.
366+
public var code: Code {
367+
return Code(rawValue: numericCast(_nsError.code))!
368+
}
369+
370+
/// Initialize an error within this domain with the given ``code``
371+
/// and ``userInfo``.
372+
public init(_ code: Code, userInfo: [String : AnyObject] = [:]) {
373+
self.init(_nsError: NSError(domain: Self._nsErrorDomain,
374+
code: numericCast(code.rawValue),
359375
userInfo: userInfo))
360376
}
361377
}

0 commit comments

Comments
 (0)