Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion Sources/Foundation/NSError.swift
Original file line number Diff line number Diff line change
Expand Up @@ -708,7 +708,9 @@ extension CocoaError: _ObjectiveCBridgeable {
}

public static func _forceBridgeFromObjectiveC(_ x: NSError, result: inout CocoaError?) {
result = _unconditionallyBridgeFromObjectiveC(x)
if !_conditionallyBridgeFromObjectiveC(x, result: &result) {
fatalError("Unable to bridge \(NSError.self) to \(self)")
}
}

public static func _conditionallyBridgeFromObjectiveC(_ x: NSError, result: inout CocoaError?) -> Bool {
Expand Down
6 changes: 6 additions & 0 deletions Tests/Foundation/TestNSError.swift
Original file line number Diff line number Diff line change
Expand Up @@ -222,4 +222,10 @@ class TestCocoaError: XCTestCase {
XCTAssertNotNil(e.underlying as? POSIXError)
XCTAssertEqual(e.underlying as? POSIXError, POSIXError.init(.EACCES))
}

func test_forceCast() {
let nsError = NSError(domain: NSCocoaErrorDomain, code: CocoaError.coderInvalidValue.rawValue)
let error = nsError as! CocoaError
XCTAssertEqual(error.errorCode, CocoaError.coderInvalidValue.rawValue)
}
}