1
- // RUN: %target-typecheck-verify-swift -swift-version 6
1
+ // There seems to be a minor bug in the diagnostic of the self-capture.
2
+ // Diagnostic algorithm does not @lvalue DeclRefExpr wrapped into LoadExpr,
3
+ // and enabling WeakLet removes the LoadExpr.
4
+ // As a result, diagnostic messages change slightly.
5
+
6
+ // RUN: %target-typecheck-verify-swift -swift-version 6 -verify-additional-prefix no-weak-let-
7
+ // RUN: %target-typecheck-verify-swift -swift-version 6 -verify-additional-prefix has-weak-let- -enable-experimental-feature WeakLet
2
8
3
9
func doStuff( _ fn : @escaping ( ) -> Int ) { }
4
10
func doVoidStuff( _ fn : @escaping ( ) -> ( ) ) { }
@@ -936,7 +942,9 @@ class TestExtensionOnOptionalSelf {
936
942
extension TestExtensionOnOptionalSelf ? {
937
943
func foo( ) {
938
944
_ = { [ weak self] in
939
- foo ( ) // expected-error {{implicit use of 'self' in closure; use 'self.' to make capture semantics explicit}}
945
+ // expected-no-weak-let-error@+2 {{implicit use of 'self' in closure; use 'self.' to make capture semantics explicit}}
946
+ // expected-has-weak-let-error@+1 {{call to method 'foo' in closure requires explicit use of 'self' to make capture semantics explicit}}
947
+ foo ( )
940
948
}
941
949
942
950
_ = {
@@ -946,8 +954,11 @@ extension TestExtensionOnOptionalSelf? {
946
954
}
947
955
948
956
_ = { [ weak self] in
949
- _ = {
950
- foo ( ) // expected-error {{implicit use of 'self' in closure; use 'self.' to make capture semantics explicit}}
957
+ _ = { // expected-has-weak-let-note {{capture 'self' explicitly to enable implicit 'self' in this closure}}
958
+ // expected-no-weak-let-error@+3 {{implicit use of 'self' in closure; use 'self.' to make capture semantics explicit}}
959
+ // expected-has-weak-let-error@+2 {{call to method 'foo' in closure requires explicit use of 'self' to make capture semantics explicit}}
960
+ // expected-has-weak-let-note@+1 {{reference 'self.' explicitly}}
961
+ foo ( )
951
962
self . foo ( )
952
963
self ? . bar ( )
953
964
}
@@ -967,7 +978,9 @@ extension TestExtensionOnOptionalSelf? {
967
978
extension TestExtensionOnOptionalSelf {
968
979
func foo( ) {
969
980
_ = { [ weak self] in
970
- foo ( ) // expected-error {{implicit use of 'self' in closure; use 'self.' to make capture semantics explicit}}
981
+ // expected-no-weak-let-error@+2 {{implicit use of 'self' in closure; use 'self.' to make capture semantics explicit}}
982
+ // expected-has-weak-let-error@+1 {{call to method 'foo' in closure requires explicit use of 'self' to make capture semantics explicit}}
983
+ foo ( )
971
984
self . foo ( )
972
985
self ? . bar ( )
973
986
}
@@ -978,8 +991,11 @@ extension TestExtensionOnOptionalSelf {
978
991
}
979
992
980
993
_ = { [ weak self] in
981
- _ = {
982
- foo ( ) // expected-error {{implicit use of 'self' in closure; use 'self.' to make capture semantics explicit}}
994
+ _ = { // expected-has-weak-let-note {{capture 'self' explicitly to enable implicit 'self' in this closure}}
995
+ // expected-no-weak-let-error@+3 {{implicit use of 'self' in closure; use 'self.' to make capture semantics explicit}}
996
+ // expected-has-weak-let-error@+2 {{call to method 'foo' in closure requires explicit use of 'self' to make capture semantics explicit}}
997
+ // expected-has-weak-let-note@+1 {{reference 'self.' explicitly}}
998
+ foo ( )
983
999
self . foo ( )
984
1000
}
985
1001
}
0 commit comments