|
| 1 | +// RUN: %target-run-simple-swift(-enable-experimental-feature NonescapableTypes) |
| 2 | +// REQUIRES: executable_test |
| 3 | +// REQUIRES: reflection |
| 4 | +// REQUIRES: swift_feature_NonescapableTypes |
| 5 | + |
| 6 | +import StdlibUnittest |
| 7 | +import Swift |
| 8 | + |
| 9 | +let suite = TestSuite("Optional") |
| 10 | + |
| 11 | +defer { runAllTests() } |
| 12 | + |
| 13 | +func isCopyable<T: ~Copyable & ~Escapable>(_: T.Type) -> Bool { false } |
| 14 | +func isCopyable<T: ~Escapable>(_: T.Type) -> Bool { true } |
| 15 | + |
| 16 | +func isBitwiseCopyable<T: ~Copyable & ~Escapable>(_: T.Type) -> Bool { false } |
| 17 | +func isBitwiseCopyable<T: BitwiseCopyable & ~Escapable>(_: T.Type) -> Bool { true } |
| 18 | + |
| 19 | +#if $NonescapableTypes |
| 20 | +func isEscapable<T: ~Escapable & ~Copyable>(_: T.Type) -> Bool { false } |
| 21 | +func isEscapable<T: ~Copyable>(_: T.Type) -> Bool { true } |
| 22 | +#endif |
| 23 | + |
| 24 | +struct TrivialStruct {} |
| 25 | +struct NoncopyableStruct: ~Copyable {} |
| 26 | +class RegularClass {} |
| 27 | + |
| 28 | +#if $NonescapableTypes |
| 29 | +struct NonescapableStruct: ~Escapable, BitwiseCopyable {} |
| 30 | +struct NoncopyableNonescapableStruct: ~Copyable, ~Escapable {} |
| 31 | +struct NonescapableNontrivialStruct: ~Escapable { |
| 32 | + let foo: RegularClass? = nil |
| 33 | +} |
| 34 | +#endif |
| 35 | + |
| 36 | +suite.test("Copyability") { |
| 37 | + expectTrue(isCopyable(Optional<TrivialStruct>.self)) |
| 38 | + expectFalse(isCopyable(Optional<NoncopyableStruct>.self)) |
| 39 | + expectTrue(isCopyable(Optional<RegularClass>.self)) |
| 40 | +#if $NonescapableTypes |
| 41 | + expectTrue(isCopyable(Optional<NonescapableStruct>.self)) |
| 42 | + expectFalse(isCopyable(Optional<NoncopyableNonescapableStruct>.self)) |
| 43 | + expectTrue(isCopyable(Optional<NonescapableNontrivialStruct>.self)) |
| 44 | +#endif |
| 45 | +} |
| 46 | + |
| 47 | +suite.test("BitwiseCopyability") { |
| 48 | + expectTrue(isBitwiseCopyable(Optional<TrivialStruct>.self)) |
| 49 | + expectFalse(isBitwiseCopyable(Optional<NoncopyableStruct>.self)) |
| 50 | + expectFalse(isBitwiseCopyable(Optional<RegularClass>.self)) |
| 51 | +#if $NonescapableTypes |
| 52 | + expectTrue(isBitwiseCopyable(Optional<NonescapableStruct>.self)) |
| 53 | + expectFalse(isBitwiseCopyable(Optional<NoncopyableNonescapableStruct>.self)) |
| 54 | + expectFalse(isBitwiseCopyable(Optional<NonescapableNontrivialStruct>.self)) |
| 55 | +#endif |
| 56 | +} |
| 57 | + |
| 58 | +#if $NonescapableTypes |
| 59 | +suite.test("Escapability") { |
| 60 | + expectTrue(isEscapable(Optional<TrivialStruct>.self)) |
| 61 | + expectTrue(isEscapable(Optional<NoncopyableStruct>.self)) |
| 62 | + expectTrue(isEscapable(Optional<RegularClass>.self)) |
| 63 | + expectFalse(isEscapable(Optional<NonescapableStruct>.self)) |
| 64 | + expectFalse(isEscapable(Optional<NoncopyableNonescapableStruct>.self)) |
| 65 | + expectFalse(isEscapable(Optional<NonescapableNontrivialStruct>.self)) |
| 66 | +} |
| 67 | +#endif |
0 commit comments