File tree 2 files changed +9
-1
lines changed
2 files changed +9
-1
lines changed Original file line number Diff line number Diff line change @@ -704,7 +704,9 @@ extension CocoaError: _ObjectiveCBridgeable {
704
704
}
705
705
706
706
public static func _forceBridgeFromObjectiveC( _ x: NSError , result: inout CocoaError ? ) {
707
- result = _unconditionallyBridgeFromObjectiveC ( x)
707
+ if !_conditionallyBridgeFromObjectiveC( x, result: & result) {
708
+ fatalError ( " Unable to bridge \( NSError . self) to \( self ) " )
709
+ }
708
710
}
709
711
710
712
public static func _conditionallyBridgeFromObjectiveC( _ x: NSError , result: inout CocoaError ? ) -> Bool {
Original file line number Diff line number Diff line change @@ -222,4 +222,10 @@ class TestCocoaError: XCTestCase {
222
222
XCTAssertNotNil ( e. underlying as? POSIXError )
223
223
XCTAssertEqual ( e. underlying as? POSIXError , POSIXError . init ( . EACCES) )
224
224
}
225
+
226
+ func test_forceCast( ) {
227
+ let nsError = NSError ( domain: NSCocoaErrorDomain, code: CocoaError . coderInvalidValue. rawValue)
228
+ let error = nsError as! CocoaError
229
+ XCTAssertEqual ( error. errorCode, CocoaError . coderInvalidValue. rawValue)
230
+ }
225
231
}
You can’t perform that action at this time.
0 commit comments