Skip to content

Commit 49539f6

Browse files
committed
tests: add a failing test for SR-2289
1 parent 524dc37 commit 49539f6

File tree

1 file changed

+46
-1
lines changed

1 file changed

+46
-1
lines changed

test/1_stdlib/Casts.swift

Lines changed: 46 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,9 @@
1717
// REQUIRES: executable_test
1818

1919
import StdlibUnittest
20-
20+
#if _runtime(_ObjC)
21+
import Foundation
22+
#endif
2123

2224
let CastsTests = TestSuite("Casts")
2325

@@ -46,4 +48,47 @@ CastsTests.test("No overrelease of existential boxes in failed casts") {
4648
bar(err)
4749
}
4850

51+
extension Int : P {}
52+
53+
#if _runtime(_ObjC)
54+
extension CFBitVector : P {
55+
static func makeImmutable(from values: Array<UInt8>) -> CFBitVector {
56+
return CFBitVectorCreate(/*allocator:*/ nil, values, values.count * 8)
57+
}
58+
}
59+
60+
extension CFMutableBitVector {
61+
static func makeMutable(from values: Array<UInt8>) -> CFMutableBitVector {
62+
return CFBitVectorCreateMutableCopy(
63+
/*allocator:*/ nil,
64+
/*capacity:*/ 0,
65+
CFBitVector.makeImmutable(from: values))
66+
}
67+
}
68+
69+
func isP<T>(_ t: T) -> Bool {
70+
return t is P
71+
}
72+
73+
CastsTests.test("Dynamic casts of CF types to protocol existentials") {
74+
expectTrue(isP(10 as Int))
75+
76+
// FIXME: SR-2289: dynamic casting of CF types to protocol existentials
77+
// should work, but there is a bug in the runtime that prevents them from
78+
// working.
79+
if !_isDebugAssertConfiguration() {
80+
// FIXME: this test should not crash. It currently crashes in optimized
81+
// mode because the optimizer assumes that the type conforms, but then the
82+
// runtime disagrees.
83+
expectCrashLater()
84+
}
85+
expectFailure {
86+
expectTrue(isP(CFBitVector.makeImmutable(from: [10, 20])))
87+
}
88+
expectFailure {
89+
expectTrue(isP(CFMutableBitVector.makeMutable(from: [10, 20])))
90+
}
91+
}
92+
#endif
93+
4994
runAllTests()

0 commit comments

Comments
 (0)