1
1
// 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
3
3
4
4
// This test validates the behavior of transfer non sendable around ownership
5
5
// constructs like non copyable types, consuming/borrowing parameters, and inout
6
6
// parameters.
7
7
8
8
// REQUIRES: concurrency
9
- // REQUIRES: swift_feature_WeakLet
9
+ // REQUIRES: swift_feature_ImmutableWeakCaptures
10
10
11
11
final class S : Sendable {
12
12
func foo( ) { }
@@ -30,15 +30,12 @@ final class CheckOptionality1: Sendable {
30
30
}
31
31
32
32
final 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?'}}
36
34
weak let x : S = getS ( )
37
35
}
38
36
39
37
final 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}}
42
39
weak var x : S ? = nil
43
40
44
41
weak var y : S ? {
@@ -48,32 +45,26 @@ final class CheckSendability1: Sendable {
48
45
}
49
46
50
47
final 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}}
53
49
weak var x : NS ? = nil
54
50
}
55
51
56
52
final class CheckSendability3 : Sendable {
57
- // expected-old-error@+1 {{'weak' must be a mutable variable, because it may change at runtime}}
58
53
weak let x : S ? = nil
59
54
}
60
55
61
56
final 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'}}
65
58
weak let x : NS ? = nil
66
59
}
67
60
68
61
final 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}}
71
63
unowned var x : S = getS ( )
72
64
}
73
65
74
66
final 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}}
77
68
unowned var x : NS = getNS ( )
78
69
}
79
70
@@ -87,14 +78,12 @@ final class CheckSendability8: Sendable {
87
78
}
88
79
89
80
final 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}}
92
82
unowned(unsafe) var x : S = getS ( )
93
83
}
94
84
95
85
final 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}}
98
87
unowned(unsafe) var x : NS = getNS ( )
99
88
}
100
89
@@ -109,17 +98,15 @@ final class CheckSendability12: Sendable {
109
98
110
99
111
100
func 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}}
113
102
weak var weakRef : S ? = strongRef
114
103
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}}
117
105
weakRef? . foo ( )
118
106
}
119
107
}
120
108
121
109
func checkWeakCapture2( _ strongRef: S ) -> @Sendable ( ) -> Void {
122
- // expected-old-error@+1 {{'weak' must be a mutable variable, because it may change at runtime}}
123
110
weak let weakRef : S ? = strongRef
124
111
return {
125
112
weakRef? . foo ( )
@@ -137,7 +124,7 @@ func checkWeakCapture3(_ strongRef: S) -> @Sendable () -> Void {
137
124
}
138
125
139
126
func 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}}
141
128
weak var weakRef : NS ? = strongRef
142
129
return {
143
130
// 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 {
147
134
}
148
135
149
136
func checkWeakCapture5( _ strongRef: NS ) -> @Sendable ( ) -> Void {
150
- // expected-old-error@+1 {{'weak' must be a mutable variable, because it may change at runtime}}
151
137
weak let weakRef : NS ? = strongRef
152
138
return {
153
139
// expected-error@+1 {{capture of 'weakRef' with non-Sendable type 'NS?' in a '@Sendable' closure}}
0 commit comments