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_swift6.swift
+70-2Lines changed: 70 additions & 2 deletions
Original file line number
Diff line number
Diff line change
@@ -608,9 +608,9 @@ class TestGithubIssue69911 {
608
608
self.x +=1
609
609
}
610
610
611
-
doVoidStuffNonEscaping{
611
+
doVoidStuffNonEscaping{ // expected-note{{capture 'self' explicitly to enable implicit 'self' in this closure}}
612
612
doVoidStuffNonEscaping{
613
-
x +=1 // expected-error{{reference to property 'x' in closure requires explicit use of 'self' to make capture semantics explicit}}
613
+
x +=1 // expected-error{{reference to property 'x' in closure requires explicit use of 'self' to make capture semantics explicit}} expected-note{{reference 'self.' explicitly}}
614
614
self.x +=1
615
615
}
616
616
}
@@ -647,6 +647,12 @@ class TestGithubIssue69911 {
647
647
}
648
648
}
649
649
}
650
+
651
+
doVoidStuff{[weak self]in
652
+
doVoidStuff{[self]in // expected-error {{value of optional type 'TestGithubIssue69911?' must be unwrapped to a value of type 'TestGithubIssue69911'}} expected-note{{coalesce using '??' to provide a default when the optional value contains 'nil'}} expected-note{{force-unwrap using '!' to abort execution if the optional value contains 'nil'}}
653
+
x +=1
654
+
}
655
+
}
650
656
}
651
657
}
652
658
@@ -923,3 +929,65 @@ class rdar129475277 {
923
929
}
924
930
}
925
931
}
932
+
933
+
classTestExtensionOnOptionalSelf{
934
+
init(){}
935
+
func bar(){}
936
+
}
937
+
938
+
extensionTestExtensionOnOptionalSelf?{
939
+
func foo(){
940
+
_ ={[weak self]in
941
+
foo() // expected-error {{implicit use of 'self' in closure; use 'self.' to make capture semantics explicit}}
942
+
self.foo()
943
+
self?.bar()
944
+
}
945
+
946
+
_ ={
947
+
foo()
948
+
self.foo()
949
+
self?.bar()
950
+
}
951
+
952
+
_ ={[weak self]in
953
+
_ ={
954
+
foo()
955
+
self.foo()
956
+
self?.bar()
957
+
}
958
+
}
959
+
960
+
_ ={[weak self]in
961
+
_ ={[self]in
962
+
foo()
963
+
self.foo()
964
+
self?.bar()
965
+
}
966
+
}
967
+
}
968
+
}
969
+
970
+
actorTestActor{
971
+
func setUp(){
972
+
doVoidStuff{[weak self]in
973
+
Task{[weak self]in
974
+
guardlet self else{return}
975
+
awaittest()
976
+
}
977
+
}
978
+
}
979
+
980
+
@MainActor
981
+
func test(){}
982
+
}
983
+
984
+
classC{
985
+
func foo(){
986
+
_ ={[self]in // expected-note {{variable other than 'self' captured here under the name 'self' does not enable implicit 'self'}} expected-warning {{capture 'self' was never used}}
987
+
guard case let self =C()else{return}
988
+
_ ={[self]in
989
+
foo() // expected-error {{call to method 'foo' in closure requires explicit use of 'self' to make capture semantics explicit}}
0 commit comments