|
13 | 13 | /// Contains tests for conversions between types which shouldn't trap.
|
14 | 14 | ///
|
15 | 15 | // -----------------------------------------------------------------------------
|
16 |
| -// RUN: %target-run-stdlib-swift |
| 16 | +// RUN: %target-run-simple-swift |
17 | 17 | // REQUIRES: executable_test
|
18 | 18 |
|
19 | 19 | import StdlibUnittest
|
20 |
| - |
| 20 | +#if _runtime(_ObjC) |
| 21 | +import Foundation |
| 22 | +#endif |
21 | 23 |
|
22 | 24 | let CastsTests = TestSuite("Casts")
|
23 | 25 |
|
@@ -46,4 +48,47 @@ CastsTests.test("No overrelease of existential boxes in failed casts") {
|
46 | 48 | bar(err)
|
47 | 49 | }
|
48 | 50 |
|
| 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 | + |
49 | 94 | runAllTests()
|
0 commit comments