Skip to content

Commit 5ed0641

Browse files
committed
[Runtime] Handle Error-conforming-to-NSObject casting fully.
I missed a case where an Error-conforming class is dynamically casted to NSObject (via NSError). Fix it.
1 parent 448a14e commit 5ed0641

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

stdlib/public/runtime/Casting.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1301,7 +1301,8 @@ static bool _dynamicCastToUnknownClassFromExistential(OpaqueValue *dest,
13011301
#if SWIFT_OBJC_INTEROP
13021302
// If we're casting to NSError, we may need a representation change,
13031303
// so fall into the general swift_dynamicCast path.
1304-
if (targetType == getNSErrorMetadata()) {
1304+
if (targetType == getNSErrorMetadata() ||
1305+
targetType == getNSObjectMetadata()) {
13051306
return swift_dynamicCast(dest, src, swift_getObjectType((HeapObject*)obj),
13061307
targetType, flags);
13071308
}

test/stdlib/ErrorBridged.swift

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -785,6 +785,11 @@ ErrorBridgingTests.test("error-to-NSObject casts") {
785785

786786
// "is" check
787787
expectTrue(error is NSObject)
788+
789+
// Unconditional cast to a dictionary.
790+
let dict = ["key" : NoisyError()]
791+
let anyOfDict = dict as AnyObject
792+
let dict2 = anyOfDict as! [String: NSObject]
788793
}
789794
}
790795

0 commit comments

Comments
 (0)