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
+11-10Lines changed: 11 additions & 10 deletions
Original file line number
Diff line number
Diff line change
@@ -185,8 +185,8 @@ class ExplicitSelfRequiredTest {
185
185
doVoidStuff{ _ =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] in}} expected-note{{reference 'self.' explicitly}} {{23-23=self.}}
186
186
doVoidStuff{ _ ="\(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] in}} expected-note{{reference 'self.' explicitly}} {{26-26=self.}}
187
187
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.}}
188
-
doVoidStuff{[y =self]in _ =method()} // expectedexpected-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.}}
189
-
doStuff({[y =self]inmethod()}) // 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.}}
188
+
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.}}
189
+
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.}}
190
190
doVoidStuff({[self=ExplicitSelfRequiredTest()]in _ =method()}) // expected-note {{variable other than 'self' captured here under the name 'self' does not enable implicit 'self'}} expected-warning {{call to method 'method' in closure requires explicit use of 'self' to make capture semantics explicit; this is an error in Swift 6}}
191
191
doStuff({[self=ExplicitSelfRequiredTest()]inmethod()}) // expected-note {{variable other than 'self' captured here under the name 'self' does not enable implicit 'self'}} expected-warning {{call to method 'method' in closure requires explicit use of 'self' to make capture semantics explicit; this is an error in Swift 6}}
192
192
doVoidStuff{ _ =self.method()}
@@ -242,9 +242,9 @@ class ExplicitSelfRequiredTest {
242
242
243
243
// If we already have a capture list, self should be added to the list
244
244
lety=1
245
-
doStuff{[y]inmethod()} // 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}} {{22-22=self.}}
245
+
doStuff{[y]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}} {{22-22=self.}}
246
246
doStuff{[ // expected-note{{capture 'self' explicitly to enable implicit 'self' in this closure}} {{16-16=self, }}
247
-
y
247
+
y // expected-warning {{capture 'y' was never used}}
248
248
]inmethod()} // expected-error {{call to method 'method' in closure requires explicit use of 'self' to make capture semantics explicit}} expected-note{{reference 'self.' explicitly}} {{14-14=self.}}
249
249
250
250
// <rdar://problem/18877391> "self." shouldn't be required in the initializer expression in a capture list
@@ -253,6 +253,7 @@ class ExplicitSelfRequiredTest {
253
253
254
254
// This should produce an error, since x is used within the inner closure.
255
255
doStuff({[myX ={x}]in4}) // 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}} {{23-23= [self] in }} expected-note{{reference 'self.' explicitly}} {{23-23=self.}}
256
+
// expected-warning @-1 {{capture 'myX' was never used}}
256
257
257
258
return42
258
259
}
@@ -261,7 +262,7 @@ class ExplicitSelfRequiredTest {
261
262
// because its `sawError` flag is set to true. To preserve the "capture 'y' was never used" warnings
262
263
// above, we put these cases in their own method.
263
264
func weakSelfError(){
264
-
doVoidStuff({[weak self]in x +=1}) // expected-error {{explicit use of 'self' is required when 'self' is optional, to make control flow explicit}} expected-note {{reference 'self?.' explicitly}} expected-warning {{variable 'self' was written to, but never read}}
265
+
doVoidStuff({[weak self]in x +=1}) // expected-error {{explicit use of 'self' is required when 'self' is optional, to make control flow explicit}} expected-note {{reference 'self?.' explicitly}}
265
266
doStuff({[weak self]in x+1}) // expected-error {{explicit use of 'self' is required when 'self' is optional, to make control flow explicit}} expected-note {{reference 'self?.' explicitly}}
266
267
doVoidStuff({[weak self]in _ =method()}) // expected-error {{explicit use of 'self' is required when 'self' is optional, to make control flow explicit}} expected-note{{reference 'self?.' explicitly}}
267
268
doStuff({[weak self]inmethod()}) // expected-error {{explicit use of 'self' is required when 'self' is optional, to make control flow explicit}} expected-note{{reference 'self?.' explicitly}}
0 commit comments