Skip to content

Commit ee269a4

Browse files
committed
Fix validation for async let thunks
1 parent d17bc35 commit ee269a4

File tree

2 files changed

+15
-5
lines changed

2 files changed

+15
-5
lines changed

lib/Sema/MiscDiagnostics.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1799,9 +1799,9 @@ static void diagnoseImplicitSelfUseInClosure(const Expr *E,
17991799
// Implicit self is always allowed in autoclosure thunks generated
18001800
// during type checking. An example of this is when storing an instance
18011801
// method as a closure (e.g. `let closure = someInstanceMethodOnSelf`).
1802-
auto isThunk =
1803-
autoclosure->getThunkKind() != AutoClosureExpr::Kind::None;
1804-
if (isThunk) {
1802+
auto thunkKind = autoclosure->getThunkKind();
1803+
if (thunkKind == AutoClosureExpr::Kind::SingleCurryThunk ||
1804+
thunkKind == AutoClosureExpr::Kind::DoubleCurryThunk) {
18051805
return true;
18061806
}
18071807

test/expr/closure/closures.swift

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1726,11 +1726,21 @@ struct TestInvalidSelfCaptureInStruct {
17261726
}
17271727
}
17281728

1729-
struct TestAsyncLet {
1729+
class TestAsyncLetInClass {
1730+
init() { }
1731+
func bar() -> Int { 0 }
1732+
func foo() async {
1733+
let _ = { // expected-note {{capture 'self' explicitly to enable implicit 'self' in this closure}}
1734+
async let x = bar() // expected-error{{call to method 'bar' in closure requires explicit use of 'self' to make capture semantics explicit}} expected-warning {{initialization of immutable value 'x' was never used; consider replacing with assignment to '_' or removing it}} expected-note{{reference 'self.' explicitly}}
1735+
}
1736+
}
1737+
}
1738+
1739+
struct TestAsyncLetInStruct {
17301740
func bar() -> Int { 0 }
17311741
func foo() async {
17321742
let _ = {
1733-
async let _ = bar()
1743+
async let x = bar() // expected-warning{{initialization of immutable value 'x' was never used; consider replacing with assignment to '_' or removing it}}
17341744
}
17351745
}
17361746
}

0 commit comments

Comments
 (0)