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
28
39func doStuff( _ fn : @escaping ( ) -> Int ) { }
410func doVoidStuff( _ fn : @escaping ( ) -> ( ) ) { }
@@ -936,7 +942,9 @@ class TestExtensionOnOptionalSelf {
936942extension TestExtensionOnOptionalSelf ? {
937943 func foo( ) {
938944 _ = { [ 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 ( )
940948 }
941949
942950 _ = {
@@ -946,8 +954,11 @@ extension TestExtensionOnOptionalSelf? {
946954 }
947955
948956 _ = { [ 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 ( )
951962 self . foo ( )
952963 self ? . bar ( )
953964 }
@@ -967,7 +978,9 @@ extension TestExtensionOnOptionalSelf? {
967978extension TestExtensionOnOptionalSelf {
968979 func foo( ) {
969980 _ = { [ 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 ( )
971984 self . foo ( )
972985 self ? . bar ( )
973986 }
@@ -978,8 +991,11 @@ extension TestExtensionOnOptionalSelf {
978991 }
979992
980993 _ = { [ 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 ( )
983999 self . foo ( )
9841000 }
9851001 }
0 commit comments