Skip to content

Commit b654cc9

Browse files
authored
Merge pull request #4107 from apple/tests-for-SR-2289
Tests for SR-2289
2 parents 928fa37 + 49539f6 commit b654cc9

File tree

1 file changed

+47
-2
lines changed

1 file changed

+47
-2
lines changed

test/1_stdlib/Casts.swift

Lines changed: 47 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,13 @@
1313
/// Contains tests for conversions between types which shouldn't trap.
1414
///
1515
// -----------------------------------------------------------------------------
16-
// RUN: %target-run-stdlib-swift
16+
// RUN: %target-run-simple-swift
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)