@@ -6,6 +6,10 @@ public class Klass {}
6
6
public class SubKlass1 : Klass { }
7
7
public class SubKlass2 : Klass { }
8
8
9
+ struct A {
10
+ var prop = " "
11
+ }
12
+
9
13
//////////////////
10
14
// Declarations //
11
15
//////////////////
@@ -14,6 +18,14 @@ func consumingUse(_ k: __owned Klass) {}
14
18
var booleanValue : Bool { false }
15
19
func nonConsumingUse( _ k: Klass ) { }
16
20
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
+
17
29
///////////
18
30
// Tests //
19
31
///////////
@@ -424,3 +436,37 @@ public func deferTest(_ x: __owned Klass) { // expected-error {{'x' used after c
424
436
}
425
437
print ( " do Something " )
426
438
}
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