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
+170Lines changed: 170 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -616,6 +616,22 @@ class C_56501 {
616
616
}
617
617
}
618
618
}
619
+
620
+
func test7(){
621
+
doVoidStuff{[self]in
622
+
func innerFunction(){
623
+
operation()
624
+
}
625
+
}
626
+
}
627
+
628
+
func test8(){
629
+
doVoidStuffNonEscaping{[self]in
630
+
func innerFunction(){
631
+
operation()
632
+
}
633
+
}
634
+
}
619
635
}
620
636
621
637
// https://github.com/apple/swift/issues/57029
@@ -812,6 +828,160 @@ public class TestImplicitSelfForWeakSelfCapture {
812
828
guardlet self =self??TestImplicitSelfForWeakSelfCapture.staticOptional else{return} // expected-warning {{value 'self' was defined but never used; consider replacing with boolean test}}
813
829
method() // expected-warning {{call to method 'method' in closure requires explicit use of 'self' to make capture semantics explicit}}
814
830
}
831
+
832
+
doVoidStuff{[weak self]in
833
+
func innerFunction1(){
834
+
method() // expected-error {{call to method 'method' in closure requires explicit use of 'self' to make capture semantics explicit}}
835
+
self?.method()
836
+
}
837
+
838
+
guardlet self else{return}
839
+
840
+
func innerFunction2(){
841
+
method()
842
+
self.method()
843
+
}
844
+
845
+
subscript(index: Int)-> Int { // expected-error {{subscript' functions may only be declared within a type}}
846
+
method()
847
+
return index
848
+
}
849
+
}
850
+
851
+
doVoidStuffNonEscaping{[weak self]in
852
+
func innerFunction1(){
853
+
method()
854
+
self?.method()
855
+
}
856
+
857
+
guardlet self else{return}
858
+
859
+
func innerFunction2(){
860
+
method()
861
+
self.method()
862
+
}
863
+
864
+
subscript(index: Int)-> Int { // expected-error {{subscript' functions may only be declared within a type}}
865
+
method()
866
+
return index
867
+
}
868
+
}
869
+
870
+
doVoidStuff{[weak self]in
871
+
guardlet self else{return}
872
+
873
+
func innerFunction1(){
874
+
doVoidStuff{ // expected-note {{capture 'self' explicitly to enable implicit 'self' in this closure}}
875
+
method() // expected-error {{call to method 'method' in closure requires explicit use of 'self' to make capture semantics explicit}} expected-note {{reference 'self.' explicitly}}
876
+
}
877
+
878
+
// This example should probably compile without an error -- seems like a bug in the impl of SE-0269
879
+
doVoidStuff{[self]in // expected-note {{variable other than 'self' captured here under the name 'self' does not enable implicit 'self'}}
880
+
method() // expected-error {{call to method 'method' in closure requires explicit use of 'self' to make capture semantics explicit}}
881
+
self.method()
882
+
}
883
+
884
+
doVoidStuff{[weak self]in
885
+
method() // expected-error {{call to method 'method' in closure requires explicit use of 'self' to make capture semantics explicit}}
method() // expected-error {{call to method 'method' in closure requires explicit use of 'self' to make capture semantics explicit}}
156
156
}
157
+
158
+
doVoidStuff{[weak self]in
159
+
func innerFunction1(){
160
+
method() // expected-error {{explicit use of 'self' is required when 'self' is optional, to make control flow explicit}} expected-note {{reference 'self?.' explicitly}}
161
+
self?.method()
162
+
}
163
+
164
+
guardlet self else{return}
165
+
166
+
func innerFunction2(){
167
+
method()
168
+
self.method()
169
+
}
170
+
}
171
+
172
+
doVoidStuffNonEscaping{[weak self]in
173
+
func innerFunction1(){
174
+
method() // 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