Skip to content

Commit efa7d90

Browse files
committed
Add an "expectedFailure" test for SR-12025 just to document the problem.
1 parent 7b6b08b commit efa7d90

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

test/Casting/Casts.swift

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -858,4 +858,25 @@ CastsTests.test("Casting Objects retained from KeyPaths to Protocols is not work
858858
expectNotNil(value as? SuperProtocol)
859859
}
860860

861+
// Known to still be broken, but we can document the issue here
862+
public protocol SomeProtocol {}
863+
extension NSString: SomeProtocol {}
864+
CastsTests.test("NSDictionary -> Dictionary casting [SR-12025]") {
865+
// Create NSDictionary with one entry
866+
var a = NSMutableDictionary()
867+
a[NSString("key")] = NSString("value")
868+
869+
let v = NSString("value")
870+
let v2 = v as? SomeProtocol
871+
expectNotNil(v2)
872+
873+
// Test casting of the dictionary
874+
let b = a as? [String:SomeProtocol]
875+
expectFailure { expectNotNil(b) } // Expect non-nil, but see nil
876+
let c = a as? [String:Any]
877+
expectNotNil(c) // Non-nil (as expected)
878+
let d = c as? [String:SomeProtocol]
879+
expectNotNil(d) // Non-nil (as expected)
880+
}
881+
861882
runAllTests()

0 commit comments

Comments
 (0)