@@ -6,6 +6,10 @@ public class Klass {}
66public class SubKlass1 : Klass { }
77public class SubKlass2 : Klass { }
88
9+ struct A {
10+ var prop = " "
11+ }
12+
913//////////////////
1014// Declarations //
1115//////////////////
@@ -14,6 +18,14 @@ func consumingUse(_ k: __owned Klass) {}
1418var booleanValue : Bool { false }
1519func nonConsumingUse( _ k: Klass ) { }
1620
21+ func consumeValue< V> ( _ v: consuming V ) { }
22+ func borrowValue< V> ( _ v: borrowing V ) { }
23+ func useValue< V> ( _ v: V ) { }
24+
25+ func consumeA( _ a: consuming A ) { }
26+ func borrowA( _ a: borrowing A ) { }
27+ func useA( _ a: A ) { }
28+
1729///////////
1830// Tests //
1931///////////
@@ -424,3 +436,37 @@ public func deferTest(_ x: __owned Klass) { // expected-error {{'x' used after c
424436 }
425437 print ( " do Something " )
426438}
439+
440+
441+ /////////////////////////
442+ // Local Binding Tests //
443+ /////////////////////////
444+
445+ func testLocalBindingUseAfterConsumeGenerics( ) {
446+ let a = A ( ) // expected-error {{'a' used after consume}}
447+ _ = consume a // expected-note {{consumed here}}
448+ consumeValue ( a) // expected-note {{used here}}
449+ borrowValue ( a) // expected-note {{used here}}
450+ useValue ( a) // expected-note {{used here}}
451+ }
452+
453+ func testLocalBindingUseAfterConsumeNoGenericFuncs( ) {
454+ let a = A ( ) // expected-error {{'a' used after consume}}
455+ _ = consume a // expected-note {{consumed here}}
456+
457+ consumeA ( a) // expected-note {{used here}}
458+ borrowA ( a) // expected-note {{used here}}
459+ useA ( a) // expected-note {{used here}}
460+ }
461+
462+ // https://github.com/swiftlang/swift/issues/83277
463+ func test_83277( ) {
464+ let values = [ 1 , 2 , 3 ] // expected-error {{'values' used after consume}}
465+ var newValues = consume values // expected-note {{consumed here}}
466+ newValues. append ( 4 )
467+
468+ _ = values. count // expected-note {{used here}}
469+ _ = values [ 0 ] // expected-note {{used here}}
470+ _ = values. first // expected-note {{used here}}
471+ _ = values. last // expected-note {{used here}}
472+ }
0 commit comments