mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
stdlib: Dictionary, Set: allow querying for a mismatched type when bridged
Swift's Dictionary and Set are typed, but when bridged to NSDictionary and NSSet they should behave accordingly, that is, allow querying for keys of arbitrary types. rdar://problem/23679193
This commit is contained in:
@@ -2154,12 +2154,37 @@ SetTestSuite.test("BridgedToObjC.Verbatim.Count") {
|
||||
}
|
||||
|
||||
SetTestSuite.test("BridgedToObjC.Verbatim.Contains") {
|
||||
let nss = getBridgedNSSetOfRefTypesBridgedVerbatim()
|
||||
let s = getBridgedNSSetOfRefTypesBridgedVerbatim()
|
||||
|
||||
expectNotEmpty(nss.member(TestObjCKeyTy(1010)))
|
||||
expectNotEmpty(nss.member(TestObjCKeyTy(2020)))
|
||||
expectNotEmpty(nss.member(TestObjCKeyTy(3030)))
|
||||
expectEmpty(nss.member(TestObjCKeyTy(4040)))
|
||||
var v: AnyObject? = s.member(TestObjCKeyTy(1010))
|
||||
expectEqual(1010, (v as! TestObjCKeyTy).value)
|
||||
let idValue10 = unsafeBitCast(v, to: UInt.self)
|
||||
|
||||
v = s.member(TestObjCKeyTy(2020))
|
||||
expectEqual(2020, (v as! TestObjCKeyTy).value)
|
||||
let idValue20 = unsafeBitCast(v, to: UInt.self)
|
||||
|
||||
v = s.member(TestObjCKeyTy(3030))
|
||||
expectEqual(3030, (v as! TestObjCKeyTy).value)
|
||||
let idValue30 = unsafeBitCast(v, to: UInt.self)
|
||||
|
||||
expectEmpty(s.member(TestObjCKeyTy(4040)))
|
||||
|
||||
// NSSet can store mixed key types. Swift's Set is typed, but when bridged
|
||||
// to NSSet, it should behave like one, and allow queries for mismatched key
|
||||
// types.
|
||||
expectEmpty(s.member(TestObjCInvalidKeyTy()))
|
||||
|
||||
for i in 0..<3 {
|
||||
expectEqual(idValue10,
|
||||
unsafeBitCast(s.member(TestObjCKeyTy(1010)), to: UInt.self))
|
||||
|
||||
expectEqual(idValue20,
|
||||
unsafeBitCast(s.member(TestObjCKeyTy(2020)), to: UInt.self))
|
||||
|
||||
expectEqual(idValue30,
|
||||
unsafeBitCast(s.member(TestObjCKeyTy(3030)), to: UInt.self))
|
||||
}
|
||||
|
||||
expectAutoreleasedKeysAndValues(unopt: (3, 0))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user