|
| 1 | +// RUN: %target-swift-emit-sil %s -verify -sil-verify-all |
| 2 | + |
| 3 | +struct Point { |
| 4 | + let x: Float |
| 5 | + let y: Float |
| 6 | +} |
| 7 | + |
| 8 | +struct ConditionallyBC<T> { |
| 9 | + var t: T |
| 10 | +} |
| 11 | +extension ConditionallyBC: BitwiseCopyable where T: BitwiseCopyable {} |
| 12 | + |
| 13 | +func test<T, BCG: BitwiseCopyable>(_ t: T, // expected-error {{'t' is borrowed and cannot be consumed}} |
| 14 | + _ bcg: BCG, // expected-error {{'bcg' is borrowed and cannot be consumed}} |
| 15 | + _ cbcg_generic: ConditionallyBC<BCG>, // expected-error {{'cbcg_generic' is borrowed and cannot be consumed}} |
| 16 | + _ maybeBCG: BCG?, // expected-error {{'maybeBCG' is borrowed and cannot be consumed}} |
| 17 | + _ maybeT: T?, // expected-error {{'maybeT' is borrowed and cannot be consumed}} |
| 18 | + _ anyBC: any BitwiseCopyable, // expected-error {{'anyBC' is borrowed and cannot be consumed}} |
| 19 | + _ x: Int, |
| 20 | + _ point: Point, |
| 21 | + _ cbcg_concrete: ConditionallyBC<Int>, |
| 22 | + _ maybeFloat: Float?) { |
| 23 | + _ = consume t // expected-note {{consumed here}} |
| 24 | + _ = consume bcg // expected-note {{consumed here}} |
| 25 | + _ = consume cbcg_generic // expected-note {{consumed here}} |
| 26 | + _ = consume maybeBCG // expected-note {{consumed here}} |
| 27 | + _ = consume maybeT // expected-note {{consumed here}} |
| 28 | + _ = consume anyBC // expected-note {{consumed here}} |
| 29 | + |
| 30 | + _ = consume x // expected-warning {{'consume' applied to bitwise-copyable type 'Int' has no effect}}{{7-15=}} |
| 31 | + _ = consume point // expected-warning {{'consume' applied to bitwise-copyable type 'Point' has no effect}}{{7-15=}} |
| 32 | + _ = consume cbcg_concrete // expected-warning {{'consume' applied to bitwise-copyable type 'ConditionallyBC<Int>' has no effect}}{{7-16=}} |
| 33 | + _ = consume maybeFloat // expected-warning {{'consume' applied to bitwise-copyable type 'Float?' has no effect}}{{8-16=}} |
| 34 | +} |
| 35 | + |
| 36 | +func proofOfUseAfterConsume() -> Int { |
| 37 | + let someInt = 10 |
| 38 | + let y = consume someInt // expected-warning {{'consume' applied to bitwise-copyable type 'Int' has no effect}} |
| 39 | + print(y) |
| 40 | + return someInt // undiagnosed use-after-consume |
| 41 | +} |
| 42 | + |
| 43 | +func moreProofs(_ share: __shared Int, |
| 44 | + _ own: __owned Int, |
| 45 | + _ snd: sending Int, // expected-error {{'snd' used after consume}} |
| 46 | + _ ino: inout Int, // expected-error {{'ino' used after consume}} |
| 47 | + _ brw: borrowing Int, // expected-error {{'brw' is borrowed and cannot be consumed}} |
| 48 | + _ csm: consuming Int // expected-error {{'csm' consumed more than once}} |
| 49 | + ) { |
| 50 | + _ = consume share // expected-warning {{'consume' applied to bitwise-copyable type 'Int' has no effect}} |
| 51 | + _ = consume own // expected-warning {{'consume' applied to bitwise-copyable type 'Int' has no effect}} |
| 52 | + let _ = (share, own) |
| 53 | + |
| 54 | + _ = consume ino // expected-note {{consumed}} |
| 55 | + _ = consume brw // expected-note {{consumed}} |
| 56 | + _ = consume csm // expected-note {{consumed}} |
| 57 | + _ = consume csm // expected-note {{consumed}} |
| 58 | + _ = consume snd // expected-note {{consumed}} |
| 59 | + _ = snd // expected-note {{used}} |
| 60 | +} // expected-note {{used here}} |
0 commit comments