Skip to content

[SILGen] Use the 'Class' existential representation for NSError subcl… #3944

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 3, 2016
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: 2 additions & 2 deletions lib/SIL/SILType.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -465,8 +465,8 @@ static bool isBridgedErrorClass(SILModule &M,
t = archetypeType->getSuperclass();

// NSError (TODO: and CFError) can be bridged.
auto errorType = M.Types.getNSErrorType();
if (t && errorType && t->isEqual(errorType)) {
auto nsErrorType = M.Types.getNSErrorType();
if (t && nsErrorType && nsErrorType->isExactSuperclassOf(t, nullptr)) {
return true;
}

Expand Down
8 changes: 8 additions & 0 deletions test/1_stdlib/ErrorBridged.swift
Original file line number Diff line number Diff line change
Expand Up @@ -582,4 +582,12 @@ ErrorBridgingTests.test("Customizing localization/recovery laziness") {
}
}

class MyNSError : NSError { }

ErrorBridgingTests.test("NSError subclass identity") {
let myNSError: Error = MyNSError(domain: "MyNSError", code: 0, userInfo: [:])
let nsError = myNSError as NSError
expectTrue(type(of: nsError) == MyNSError.self)
}

runAllTests()
13 changes: 13 additions & 0 deletions test/SILGen/objc_error.swift
Original file line number Diff line number Diff line change
Expand Up @@ -95,3 +95,16 @@ func testProduceOptionalError() -> Error? {
// CHECK: function_ref @swift_convertNSErrorToError
return produceOptionalError();
}

class MyNSError : NSError {
override init() {
super.init(domain: "MyNSError", code: 0, userInfo: [:])
}
}

// CHECK-LABEL: sil hidden @_TF10objc_error14eraseMyNSError
// CHECK-NOT: return
// CHECK: init_existential_ref
func eraseMyNSError() -> Error {
return MyNSError()
}