|
1 | | -// RUN: %target-typecheck-verify-swift -disable-availability-checking -enable-experimental-feature NonescapableTypes -disable-experimental-parser-round-trip -enable-experimental-feature NoncopyableGenerics -enable-experimental-feature BitwiseCopyable |
| 1 | +// RUN: %target-typecheck-verify-swift -disable-availability-checking -enable-experimental-feature NonescapableTypes -disable-experimental-parser-round-trip -enable-experimental-feature NoncopyableGenerics |
2 | 2 | // REQUIRES: asserts |
3 | | -// REQUIRES: noncopyable_generics |
4 | | -// REQUIRES: nonescapable_types |
5 | 3 |
|
6 | 4 | struct Container { |
7 | 5 | let ptr: UnsafeRawBufferPointer |
8 | 6 | } |
9 | 7 |
|
10 | | -struct AnotherBufferView : ~Escapable, _BitwiseCopyable { |
11 | | - let ptr: UnsafeRawBufferPointer |
12 | | - @_unsafeNonescapableResult |
13 | | - init(_ ptr: UnsafeRawBufferPointer) { |
14 | | - self.ptr = ptr |
15 | | - } |
16 | | -} |
17 | | - |
18 | 8 | struct BufferView : ~Escapable { |
19 | 9 | let ptr: UnsafeRawBufferPointer |
20 | 10 | @_unsafeNonescapableResult |
21 | 11 | init(_ ptr: UnsafeRawBufferPointer) { |
22 | 12 | self.ptr = ptr |
23 | 13 | } |
24 | | - init(_ c: borrowing Container) -> _borrow(c) Self { // expected-error{{invalid lifetime dependence on bitwise copyable type}} |
25 | | - self.ptr = c.ptr |
| 14 | + init(_ ptr: UnsafeRawBufferPointer, _ arr: borrowing Array<Int>) -> _borrow(arr) Self { |
| 15 | + self.ptr = ptr |
26 | 16 | return self |
27 | 17 | } |
28 | | - init(_ bv: borrowing AnotherBufferView) -> _borrow(bv) Self { |
29 | | - self.ptr = bv.ptr |
| 18 | + init(_ ptr: UnsafeRawBufferPointer, _ arr: borrowing Array<Double>) -> _borrow(arr) Self { |
| 19 | + self.ptr = ptr |
| 20 | + } |
| 21 | + // TODO: Once Optional is ~Escapable, the error will go away |
| 22 | + init?(_ ptr: UnsafeRawBufferPointer, _ arr: borrowing Array<Float>) -> _borrow(arr) Self? { // expected-error{{lifetime dependence can only be specified on ~Escapable results}} |
| 23 | + if (Int.random(in: 1..<100) == 0) { |
| 24 | + return nil |
| 25 | + } |
| 26 | + self.ptr = ptr |
| 27 | + } |
| 28 | + init?(_ ptr: UnsafeRawBufferPointer, _ arr: borrowing Array<String>) -> _borrow(arr) Self? { // expected-error{{lifetime dependence can only be specified on ~Escapable results}} |
| 29 | + if (Int.random(in: 1..<100) == 0) { |
| 30 | + return nil |
| 31 | + } |
| 32 | + self.ptr = ptr |
30 | 33 | return self |
31 | 34 | } |
32 | 35 | } |
|
0 commit comments