Skip to content

Commit 7383696

Browse files
authored
Merge pull request #3944 from DougGregor/rdar-27658748
2 parents 58cce27 + 3f960e3 commit 7383696

File tree

3 files changed

+23
-2
lines changed

3 files changed

+23
-2
lines changed

lib/SIL/SILType.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -465,8 +465,8 @@ static bool isBridgedErrorClass(SILModule &M,
465465
t = archetypeType->getSuperclass();
466466

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

test/1_stdlib/ErrorBridged.swift

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -582,4 +582,12 @@ ErrorBridgingTests.test("Customizing localization/recovery laziness") {
582582
}
583583
}
584584

585+
class MyNSError : NSError { }
586+
587+
ErrorBridgingTests.test("NSError subclass identity") {
588+
let myNSError: Error = MyNSError(domain: "MyNSError", code: 0, userInfo: [:])
589+
let nsError = myNSError as NSError
590+
expectTrue(type(of: nsError) == MyNSError.self)
591+
}
592+
585593
runAllTests()

test/SILGen/objc_error.swift

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,3 +95,16 @@ func testProduceOptionalError() -> Error? {
9595
// CHECK: function_ref @swift_convertNSErrorToError
9696
return produceOptionalError();
9797
}
98+
99+
class MyNSError : NSError {
100+
override init() {
101+
super.init(domain: "MyNSError", code: 0, userInfo: [:])
102+
}
103+
}
104+
105+
// CHECK-LABEL: sil hidden @_TF10objc_error14eraseMyNSError
106+
// CHECK-NOT: return
107+
// CHECK: init_existential_ref
108+
func eraseMyNSError() -> Error {
109+
return MyNSError()
110+
}

0 commit comments

Comments
 (0)