Skip to content

Commit 369e20f

Browse files
committed
Put back unused capture warnings
1 parent ccdf807 commit 369e20f

File tree

1 file changed

+11
-10
lines changed

1 file changed

+11
-10
lines changed

test/expr/closure/closures.swift

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -185,8 +185,8 @@ class ExplicitSelfRequiredTest {
185185
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.}}
186186
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.}}
187187
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] 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}} {{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] 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}} {{16-16=self, }} expected-note{{reference 'self.' explicitly}} {{29-29=self.}}
190190
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}}
191191
doStuff({ [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}}
192192
doVoidStuff { _ = self.method() }
@@ -242,9 +242,9 @@ class ExplicitSelfRequiredTest {
242242

243243
// If we already have a capture list, self should be added to the list
244244
let y = 1
245-
doStuff { [y] 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}} {{16-16=self, }} expected-note{{reference 'self.' explicitly}} {{22-22=self.}}
245+
doStuff { [y] 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}} {{16-16=self, }} expected-note{{reference 'self.' explicitly}} {{22-22=self.}}
246246
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}}
248248
] in method() } // 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.}}
249249

250250
// <rdar://problem/18877391> "self." shouldn't be required in the initializer expression in a capture list
@@ -253,6 +253,7 @@ class ExplicitSelfRequiredTest {
253253

254254
// This should produce an error, since x is used within the inner closure.
255255
doStuff({ [myX = {x}] in 4 }) // 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}}
256257

257258
return 42
258259
}
@@ -261,7 +262,7 @@ class ExplicitSelfRequiredTest {
261262
// because its `sawError` flag is set to true. To preserve the "capture 'y' was never used" warnings
262263
// above, we put these cases in their own method.
263264
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}}
265266
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}}
266267
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}}
267268
doStuff({ [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}}
@@ -625,7 +626,7 @@ func callitArgsFn<T>(_ : Int, _ f: () -> () -> T) -> T {
625626
f()()
626627
}
627628

628-
func callitGenericArg<T>(_ a: T, _ f: () -> T) -> T {
629+
func callitGenericArg<T>(_ a: T, _ f: () -> T) -> T {
629630
f()
630631
}
631632

@@ -641,7 +642,7 @@ func testSR13239_Tuple() -> Int {
641642
// expected-error@+2{{conflicting arguments to generic parameter 'T' ('()' vs. 'Int')}}
642643
// expected-note@+1:3{{generic parameter 'T' inferred as 'Int' from context}}
643644
callitTuple(1) { // expected-note@:18{{generic parameter 'T' inferred as '()' from closure return expression}}
644-
(print("hello"), 0)
645+
(print("hello"), 0)
645646
}
646647
}
647648

@@ -657,21 +658,21 @@ func testSR13239_Args() -> Int {
657658
// expected-error@+2{{conflicting arguments to generic parameter 'T' ('()' vs. 'Int')}}
658659
// expected-note@+1:3{{generic parameter 'T' inferred as 'Int' from context}}
659660
callitArgs(1) { // expected-note@:17{{generic parameter 'T' inferred as '()' from closure return expression}}
660-
print("hello")
661+
print("hello")
661662
}
662663
}
663664

664665
func testSR13239_ArgsFn() -> Int {
665666
// expected-error@+2{{conflicting arguments to generic parameter 'T' ('()' vs. 'Int')}}
666667
// expected-note@+1:3{{generic parameter 'T' inferred as 'Int' from context}}
667668
callitArgsFn(1) { // expected-note@:19{{generic parameter 'T' inferred as '()' from closure return expression}}
668-
{ print("hello") }
669+
{ print("hello") }
669670
}
670671
}
671672

672673
func testSR13239MultiExpr() -> Int {
673674
callit {
674-
print("hello")
675+
print("hello")
675676
return print("hello") // expected-error {{cannot convert return expression of type '()' to return type 'Int'}}
676677
}
677678
}

0 commit comments

Comments
 (0)