|
11 | 11 | // Future tests for LifetimeDependenceDiagnostics.
|
12 | 12 | // REQUIRES: disabled
|
13 | 13 |
|
| 14 | +struct BV : ~Escapable { |
| 15 | + let p: UnsafeRawPointer |
| 16 | + let i: Int |
| 17 | + |
| 18 | + @_unsafeNonescapableResult |
| 19 | + init(_ p: UnsafeRawPointer, _ i: Int) { |
| 20 | + self.p = p |
| 21 | + self.i = i |
| 22 | + } |
| 23 | +} |
| 24 | + |
| 25 | +// Nonescapable wrapper. |
| 26 | +struct NEBV : ~Escapable { |
| 27 | + var bv: BV |
| 28 | + |
| 29 | + // Test lifetime inheritance through initialization. |
| 30 | + init(_ bv: consuming BV) { |
| 31 | + self.bv = bv |
| 32 | + } |
| 33 | + |
| 34 | + var view: BV { |
| 35 | + _read { |
| 36 | + yield bv |
| 37 | + } |
| 38 | + _modify { |
| 39 | + yield &bv |
| 40 | + } |
| 41 | + } |
| 42 | + |
| 43 | + func borrowedView() -> dependsOn(scoped self) BV { |
| 44 | + bv |
| 45 | + } |
| 46 | +} |
| 47 | + |
| 48 | +// Noncopyable, Nonescapable wrapper. |
| 49 | +struct NCNEBV : ~Copyable, ~Escapable { |
| 50 | + var bv: BV |
| 51 | + |
| 52 | + // Test lifetime inheritance through initialization. |
| 53 | + init(_ bv: consuming BV) { |
| 54 | + self.bv = bv |
| 55 | + } |
| 56 | + |
| 57 | + var view: BV { |
| 58 | + _read { |
| 59 | + yield bv |
| 60 | + } |
| 61 | + _modify { |
| 62 | + yield &bv |
| 63 | + } |
| 64 | + } |
| 65 | + |
| 66 | + func borrowedView() -> dependsOn(scoped self) BV { |
| 67 | + bv |
| 68 | + } |
| 69 | +} |
| 70 | + |
| 71 | +func ncnebv_consume(_: consuming NCNEBV) {} |
| 72 | +func bv_consume(_: consuming BV) {} |
14 | 73 |
|
15 | 74 | // =============================================================================
|
16 | 75 | // Diagnostics that should fail.
|
@@ -42,3 +101,30 @@ func bvcons_capture_escapelet(bv: consuming BV) -> ()->Int {
|
42 | 101 | // expected-note @-1 {{this use causes the lifetime-dependent value to escape}}
|
43 | 102 | return closure
|
44 | 103 | }
|
| 104 | + |
| 105 | +// ============================================================================= |
| 106 | +// Can't write lit tests because move-only diagnostics are broken. |
| 107 | + |
| 108 | +func nebv_consume(_: consuming NEBV) {} |
| 109 | + |
| 110 | +// FIXME: consume operator diagnostics does not report a line number for "used here" |
| 111 | +func nebv_consume_borrow(nebv: NEBV) { |
| 112 | + let bv = nebv.borrowedView() // expected-note {{conflicting access is here}} |
| 113 | + nebv_consume(nebv) // expected-error {{overlapping accesses to 'nebv', but deinitialization requires exclusive access}} |
| 114 | + bv_consume(bv) |
| 115 | +} |
| 116 | + |
| 117 | +// FIXME: consume operator diagnostics does not report a line number for "used here" |
| 118 | +func nebv_consume_borrow(nebv: consuming NEBV) { // expected-error {{'nebv' used after consume}} |
| 119 | + let bv = nebv.borrowedView() // expected-note {{conflicting access is here}} |
| 120 | + _ = consume nebv // expected-error {{overlapping accesses to 'nebv', but modification requires exclusive access}} |
| 121 | + // expected-note @-1{{consumed here}} |
| 122 | + bv_consume(bv) |
| 123 | +} |
| 124 | + |
| 125 | +// FIXME: consume operator diagnostics does not report a line number for "used here" |
| 126 | +func ncnebv_consume_borrow(ncnebv: NCNEBV) { |
| 127 | + let bv = ncnebv.borrowedView() // expected-note {{conflicting access is here}} |
| 128 | + ncnebv_consume(ncnebv) // expected-error {{overlapping accesses to 'nebv', but deinitialization requires exclusive access}} |
| 129 | + bv_consume(bv) |
| 130 | +} |
0 commit comments