11// RUN: %target-swift-frontend -emit-sil -swift-version 6 -target %target-swift-5.1-abi-triple -verify -verify-additional-prefix old- %s -o /dev/null
2- // RUN: %target-swift-frontend -emit-sil -swift-version 6 -target %target-swift-5.1-abi-triple -verify -verify-additional-prefix new- -enable-upcoming-feature WeakLet %s -o /dev/null
2+ // RUN: %target-swift-frontend -emit-sil -swift-version 6 -target %target-swift-5.1-abi-triple -verify -verify-additional-prefix new- -enable-upcoming-feature ImmutableWeakCaptures %s -o /dev/null
33
44// This test validates the behavior of transfer non sendable around ownership
55// constructs like non copyable types, consuming/borrowing parameters, and inout
66// parameters.
77
88// REQUIRES: concurrency
9- // REQUIRES: swift_feature_WeakLet
9+ // REQUIRES: swift_feature_ImmutableWeakCaptures
1010
1111final class S : Sendable {
1212 func foo( ) { }
@@ -30,15 +30,12 @@ final class CheckOptionality1: Sendable {
3030}
3131
3232final class CheckOptionality2 : Sendable {
33- // expected-old-error@+3 {{'weak' must be a mutable variable, because it may change at runtime}}
34- // expected-old-error@+2 {{'weak' variable should have optional type 'S?'}}
35- // expected-new-error@+1 {{'weak' variable should have optional type 'S?'}}
33+ // expected-error@+1 {{'weak' variable should have optional type 'S?'}}
3634 weak let x : S = getS ( )
3735}
3836
3937final class CheckSendability1 : Sendable {
40- // expected-old-error@+2 {{stored property 'x' of 'Sendable'-conforming class 'CheckSendability1' is mutable}}
41- // expected-new-error@+1 {{stored property 'x' of 'Sendable'-conforming class 'CheckSendability1' is mutable}}
38+ // expected-error@+1 {{stored property 'x' of 'Sendable'-conforming class 'CheckSendability1' is mutable}}
4239 weak var x : S ? = nil
4340
4441 weak var y : S ? {
@@ -48,32 +45,26 @@ final class CheckSendability1: Sendable {
4845}
4946
5047final class CheckSendability2 : Sendable {
51- // expected-old-error@+2 {{stored property 'x' of 'Sendable'-conforming class 'CheckSendability2' is mutable}}
52- // expected-new-error@+1 {{stored property 'x' of 'Sendable'-conforming class 'CheckSendability2' is mutable}}
48+ // expected-error@+1 {{stored property 'x' of 'Sendable'-conforming class 'CheckSendability2' is mutable}}
5349 weak var x : NS ? = nil
5450}
5551
5652final class CheckSendability3 : Sendable {
57- // expected-old-error@+1 {{'weak' must be a mutable variable, because it may change at runtime}}
5853 weak let x : S ? = nil
5954}
6055
6156final class CheckSendability4 : Sendable {
62- // expected-old-error@+3 {{'weak' must be a mutable variable, because it may change at runtime}}
63- // expected-old-error@+2 {{stored property 'x' of 'Sendable'-conforming class 'CheckSendability4' contains non-Sendable type 'NS'}}
64- // expected-new-error@+1 {{stored property 'x' of 'Sendable'-conforming class 'CheckSendability4' contains non-Sendable type 'NS'}}
57+ // expected-error@+1 {{stored property 'x' of 'Sendable'-conforming class 'CheckSendability4' contains non-Sendable type 'NS'}}
6558 weak let x : NS ? = nil
6659}
6760
6861final class CheckSendability5 : Sendable {
69- // expected-old-error@+2 {{stored property 'x' of 'Sendable'-conforming class 'CheckSendability5' is mutable}}
70- // expected-new-error@+1 {{stored property 'x' of 'Sendable'-conforming class 'CheckSendability5' is mutable}}
62+ // expected-error@+1 {{stored property 'x' of 'Sendable'-conforming class 'CheckSendability5' is mutable}}
7163 unowned var x : S = getS ( )
7264}
7365
7466final class CheckSendability6 : Sendable {
75- // expected-old-error@+2 {{stored property 'x' of 'Sendable'-conforming class 'CheckSendability6' is mutable}}
76- // expected-new-error@+1 {{stored property 'x' of 'Sendable'-conforming class 'CheckSendability6' is mutable}}
67+ // expected-error@+1 {{stored property 'x' of 'Sendable'-conforming class 'CheckSendability6' is mutable}}
7768 unowned var x : NS = getNS ( )
7869}
7970
@@ -87,14 +78,12 @@ final class CheckSendability8: Sendable {
8778}
8879
8980final class CheckSendability9 : Sendable {
90- // expected-old-error@+2 {{stored property 'x' of 'Sendable'-conforming class 'CheckSendability9' is mutable}}
91- // expected-new-error@+1 {{stored property 'x' of 'Sendable'-conforming class 'CheckSendability9' is mutable}}
81+ // expected-error@+1 {{stored property 'x' of 'Sendable'-conforming class 'CheckSendability9' is mutable}}
9282 unowned(unsafe) var x : S = getS ( )
9383}
9484
9585final class CheckSendability10 : Sendable {
96- // expected-old-error@+2 {{stored property 'x' of 'Sendable'-conforming class 'CheckSendability10' is mutable}}
97- // expected-new-error@+1 {{stored property 'x' of 'Sendable'-conforming class 'CheckSendability10' is mutable}}
86+ // expected-error@+1 {{stored property 'x' of 'Sendable'-conforming class 'CheckSendability10' is mutable}}
9887 unowned(unsafe) var x : NS = getNS ( )
9988}
10089
@@ -109,17 +98,15 @@ final class CheckSendability12: Sendable {
10998
11099
111100func checkWeakCapture1( _ strongRef: S ) -> @Sendable ( ) -> Void {
112- // expected-new- warning@+1 {{variable 'weakRef' was never mutated; consider changing to 'let' constant}}
101+ // expected-warning@+1 {{variable 'weakRef' was never mutated; consider changing to 'let' constant}}
113102 weak var weakRef : S ? = strongRef
114103 return {
115- // expected-old-error@+2 {{reference to captured var 'weakRef' in concurrently-executing code}}
116- // expected-new-error@+1 {{reference to captured var 'weakRef' in concurrently-executing code}}
104+ // expected-error@+1 {{reference to captured var 'weakRef' in concurrently-executing code}}
117105 weakRef? . foo ( )
118106 }
119107}
120108
121109func checkWeakCapture2( _ strongRef: S ) -> @Sendable ( ) -> Void {
122- // expected-old-error@+1 {{'weak' must be a mutable variable, because it may change at runtime}}
123110 weak let weakRef : S ? = strongRef
124111 return {
125112 weakRef? . foo ( )
@@ -137,7 +124,7 @@ func checkWeakCapture3(_ strongRef: S) -> @Sendable () -> Void {
137124}
138125
139126func checkWeakCapture4( _ strongRef: NS ) -> @Sendable ( ) -> Void {
140- // expected-new- warning@+1 {{variable 'weakRef' was never mutated; consider changing to 'let' constant}}
127+ // expected-warning@+1 {{variable 'weakRef' was never mutated; consider changing to 'let' constant}}
141128 weak var weakRef : NS ? = strongRef
142129 return {
143130 // expected-error@+2 {{capture of 'weakRef' with non-Sendable type 'NS?' in a '@Sendable' closure}}
@@ -147,7 +134,6 @@ func checkWeakCapture4(_ strongRef: NS) -> @Sendable () -> Void {
147134}
148135
149136func checkWeakCapture5( _ strongRef: NS ) -> @Sendable ( ) -> Void {
150- // expected-old-error@+1 {{'weak' must be a mutable variable, because it may change at runtime}}
151137 weak let weakRef : NS ? = strongRef
152138 return {
153139 // expected-error@+1 {{capture of 'weakRef' with non-Sendable type 'NS?' in a '@Sendable' closure}}
0 commit comments