You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: test/expr/closure/closures.swift
+16-16Lines changed: 16 additions & 16 deletions
Original file line number
Diff line number
Diff line change
@@ -176,8 +176,8 @@ class ExplicitSelfRequiredTest {
176
176
doVoidStuff({ _ ="\(x)"}) // expected-error {{reference to property 'x' in closure requires explicit use of 'self' to make capture semantics explicit}} expected-note{{capture 'self' explicitly to enable implicit 'self' in this closure}} {{18-18= [self] in}} expected-note{{reference 'self.' explicitly}} {{26-26=self.}}
177
177
doVoidStuff({[y =self]in x +=1}) // expected-warning {{capture 'y' was never used}} expected-error {{reference to property 'x' in closure requires explicit use of 'self' to make capture semantics explicit}} expected-note{{capture 'self' explicitly to enable implicit 'self' in this closure}} {{20-20=self, }} expected-note{{reference 'self.' explicitly}} {{33-33=self.}}
178
178
doStuff({[y =self]in x+1}) // expected-warning {{capture 'y' was never used}} expected-error {{reference to property 'x' in closure requires explicit use of 'self' to make capture semantics explicit}} expected-note{{capture 'self' explicitly to enable implicit 'self' in this closure}} {{16-16=self, }} expected-note{{reference 'self.' explicitly}} {{29-29=self.}}
179
-
doVoidStuff({[self=ExplicitSelfRequiredTest()]in x +=1}) // expected-note {{variable other than 'self' captured here under the name 'self' does not enable implicit 'self'}} expected-error {{reference to property 'x' in closure requires explicit use of 'self' to make capture semantics explicit}} expected-warning {{capture 'self' was never used}}
180
-
doStuff({[self=ExplicitSelfRequiredTest()]in x+1}) // expected-note {{variable other than 'self' captured here under the name 'self' does not enable implicit 'self'}} expected-error {{reference to property 'x' in closure requires explicit use of 'self' to make capture semantics explicit}} expected-warning {{capture 'self' was never used}}
179
+
doVoidStuff({[self=ExplicitSelfRequiredTest()]in x +=1}) // expected-note {{variable other than 'self' captured here under the name 'self' does not enable implicit 'self'}} expected-error {{reference to property 'x' in closure requires explicit use of 'self' to make capture semantics explicit}}
180
+
doStuff({[self=ExplicitSelfRequiredTest()]in x+1}) // expected-note {{variable other than 'self' captured here under the name 'self' does not enable implicit 'self'}} expected-error {{reference to property 'x' in closure requires explicit use of 'self' to make capture semantics explicit}}
181
181
182
182
// Methods follow the same rules as properties, uses of 'self' without capturing must be marked with "self."
183
183
doStuff{method()} // expected-error {{call to method 'method' in closure requires explicit use of 'self' to make capture semantics explicit}} expected-note{{capture 'self' explicitly to enable implicit 'self' in this closure}} {{14-14= [self] in}} expected-note{{reference 'self.' explicitly}} {{15-15=self.}}
@@ -186,8 +186,8 @@ class ExplicitSelfRequiredTest {
186
186
doVoidStuff{()->()in _ =method()} // expected-error {{call to method 'method' in closure requires explicit use of 'self' to make capture semantics explicit}} expected-note{{capture 'self' explicitly to enable implicit 'self' in this closure}} {{18-18= [self]}} expected-note{{reference 'self.' explicitly}} {{35-35=self.}}
187
187
doVoidStuff{[y =self]in _ =method()} // expected-warning {{capture 'y' was never used}} expected-error {{call to method 'method' in closure requires explicit use of 'self' to make capture semantics explicit}} expected-note{{capture 'self' explicitly to enable implicit 'self' in this closure}} {{20-20=self, }} expected-note{{reference 'self.' explicitly}} {{37-37=self.}}
188
188
doStuff({[y =self]inmethod()}) // expected-warning {{capture 'y' was never used}} expected-error {{call to method 'method' in closure requires explicit use of 'self' to make capture semantics explicit}} expected-note{{capture 'self' explicitly to enable implicit 'self' in this closure}} {{16-16=self, }} expected-note{{reference 'self.' explicitly}} {{29-29=self.}}
189
-
doVoidStuff({[self=ExplicitSelfRequiredTest()]in _ =method()}) // expected-note {{variable other than 'self' captured here under the name 'self' does not enable implicit 'self'}} expected-error {{call to method 'method' in closure requires explicit use of 'self' to make capture semantics explicit}} expected-warning {{capture 'self' was never used}}
190
-
doStuff({[self=ExplicitSelfRequiredTest()]inmethod()}) // expected-note {{variable other than 'self' captured here under the name 'self' does not enable implicit 'self'}} expected-error {{call to method 'method' in closure requires explicit use of 'self' to make capture semantics explicit}} expected-warning {{capture 'self' was never used}}
189
+
doVoidStuff({[self=ExplicitSelfRequiredTest()]in _ =method()}) // expected-note {{variable other than 'self' captured here under the name 'self' does not enable implicit 'self'}} expected-error {{call to method 'method' in closure requires explicit use of 'self' to make capture semantics explicit}}
190
+
doStuff({[self=ExplicitSelfRequiredTest()]inmethod()}) // expected-note {{variable other than 'self' captured here under the name 'self' does not enable implicit 'self'}} expected-error {{call to method 'method' in closure requires explicit use of 'self' to make capture semantics explicit}}
191
191
doVoidStuff{ _ =self.method()}
192
192
doVoidStuff{[self]in _ =method()}
193
193
doVoidStuff{[self=self]in _ =method()}
@@ -261,12 +261,12 @@ class ExplicitSelfRequiredTest {
261
261
// because its `sawError` flag is set to true. To preserve the "capture 'y' was never used" warnings
262
262
// above, we put these cases in their own method.
263
263
func weakSelfError(){
264
-
doVoidStuff({[weak self]in x +=1}) // expected-error {{reference to property 'x' in closure requires explicit use of 'self' to make capture semantics explicit}} expected-warning {{variable 'self' was written to, but never read}}
265
-
doVoidStuffNonEscaping({[weak self]in x +=1}) // expected-warning {{reference to property 'x' in closure requires explicit use of 'self' to make capture semantics explicit}} expected-warning {{variable 'self' was written to, but never read}}
266
-
doStuff({[weak self]in x+1}) // expected-error {{reference to property 'x' in closure requires explicit use of 'self' to make capture semantics explicit}} expected-warning {{variable 'self' was written to, but never read}}
267
-
doVoidStuff({[weak self]in _ =method()}) // expected-error {{call to method 'method' in closure requires explicit use of 'self' to make capture semantics explicit}} expected-warning {{variable 'self' was written to, but never read}}
268
-
doVoidStuffNonEscaping({[weak self]in _ =method()}) // expected-warning {{call to method 'method' in closure requires explicit use of 'self' to make capture semantics explicit}} expected-warning {{variable 'self' was written to, but never read}}
269
-
doStuff({[weak self]inmethod()}) // expected-error {{call to method 'method' in closure requires explicit use of 'self' to make capture semantics explicit}} expected-warning {{variable 'self' was written to, but never read}}
264
+
doVoidStuff({[weak self]in x +=1}) // expected-error {{reference to property 'x' in closure requires explicit use of 'self' to make capture semantics explicit}}
265
+
doVoidStuffNonEscaping({[weak self]in x +=1}) // expected-warning {{reference to property 'x' in closure requires explicit use of 'self' to make capture semantics explicit}}
266
+
doStuff({[weak self]in x+1}) // expected-error {{reference to property 'x' in closure requires explicit use of 'self' to make capture semantics explicit}}
267
+
doVoidStuff({[weak self]in _ =method()}) // expected-error {{call to method 'method' in closure requires explicit use of 'self' to make capture semantics explicit}}
268
+
doVoidStuffNonEscaping({[weak self]in _ =method()}) // expected-warning {{call to method 'method' in closure requires explicit use of 'self' to make capture semantics explicit}}
269
+
doStuff({[weak self]inmethod()}) // expected-error {{call to method 'method' in closure requires explicit use of 'self' to make capture semantics explicit}}
270
270
}
271
271
}
272
272
@@ -759,14 +759,14 @@ public class TestImplicitSelfForWeakSelfCapture {
759
759
}
760
760
761
761
doVoidStuff{[weak self]in
762
-
guardlet self =selfelse{return} // expected-warning {{value 'self' was defined but never used; consider replacing with boolean test}}
762
+
guardlet self =selfelse{return}
763
763
doVoidStuff{ // expected-note {{capture 'self' explicitly to enable implicit 'self' in this closure}}
764
764
method() // expected-error {{call to method 'method' in closure requires explicit use of 'self' to make capture semantics explicit}} expected-note {{reference 'self.' explicitly}}
765
765
}
766
766
}
767
767
768
768
doVoidStuff{[weak self]in
769
-
guardlet self =self??TestImplicitSelfForWeakSelfCapture.staticOptional else{return} // expected-warning {{value 'self' was defined but never used; consider replacing with boolean test}}
guardlet self =selfelse{return} // expected-warning {{value 'self' was defined but never used; consider replacing with boolean test}}
793
+
guardlet self =selfelse{return}
794
794
method() // expected-warning {{call to method 'method' in closure requires explicit use of 'self' to make capture semantics explicit}}
795
795
}
796
796
797
797
doVoidStuffNonEscaping{[weak self]in
798
-
guardlet self =selfelse{return} // expected-warning {{value 'self' was defined but never used; consider replacing with boolean test}}
798
+
guardlet self =selfelse{return}
799
799
doVoidStuff{ // expected-note {{capture 'self' explicitly to enable implicit 'self' in this closure}}
800
800
method() // expected-error {{call to method 'method' in closure requires explicit use of 'self' to make capture semantics explicit}} expected-note {{reference 'self.' explicitly}}
801
801
}
802
802
}
803
803
804
804
doVoidStuffNonEscaping{[weak self]in
805
-
guardlet self =self??TestImplicitSelfForWeakSelfCapture.staticOptional else{return} // expected-warning {{value 'self' was defined but never used; consider replacing with boolean test}}
0 commit comments