Skip to content

Commit 47e1151

Browse files
authored
Merge pull request #4652 from DougGregor/document-error-userinfo-type
Tighten up and document the type of Error._userInfo somewhat.
2 parents b5e5557 + 77a3609 commit 47e1151

File tree

2 files changed

+9
-5
lines changed

2 files changed

+9
-5
lines changed

stdlib/public/SDK/Foundation/NSError.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,7 @@ public func _swift_Foundation_getErrorDefaultUserInfo(_ error: Error)
287287
extension NSError : Error {
288288
public var _domain: String { return domain }
289289
public var _code: Int { return code }
290-
public var _userInfo: Any? { return userInfo }
290+
public var _userInfo: AnyObject? { return userInfo as NSDictionary }
291291

292292
/// The "embedded" NSError is itself.
293293
public func _getEmbeddedNSError() -> AnyObject? {
@@ -304,8 +304,8 @@ extension CFError : Error {
304304
return CFErrorGetCode(self)
305305
}
306306

307-
public var _userInfo: Any? {
308-
return CFErrorCopyUserInfo(self) as Any
307+
public var _userInfo: AnyObject? {
308+
return CFErrorCopyUserInfo(self) as AnyObject
309309
}
310310

311311
/// The "embedded" NSError is itself.

stdlib/public/core/ErrorType.swift

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,11 @@ import SwiftShims
113113
public protocol Error {
114114
var _domain: String { get }
115115
var _code: Int { get }
116-
var _userInfo: Any? { get }
116+
117+
// Note: _userInfo is always an NSDictionary, but we cannot use that type here
118+
// because the standard library cannot depend on Foundation. However, the
119+
// underscore implies that we control all implementations of this requirement.
120+
var _userInfo: AnyObject? { get }
117121

118122
#if _runtime(_ObjC)
119123
func _getEmbeddedNSError() -> AnyObject?
@@ -203,7 +207,7 @@ extension Error {
203207
return String(reflecting: type(of: self))
204208
}
205209

206-
public var _userInfo: Any? {
210+
public var _userInfo: AnyObject? {
207211
#if _runtime(_ObjC)
208212
return _stdlib_getErrorDefaultUserInfo(self)
209213
#else

0 commit comments

Comments
 (0)