Skip to content

Commit 7d897fd

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

File tree

2 files changed

+14
-4
lines changed

2 files changed

+14
-4
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: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1726,7 +1726,17 @@ 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 _ = bar() // expected-error{{call to method 'bar' in closure requires explicit use of 'self' to make capture semantics explicit}} expected-note{{reference 'self.' explicitly}}
1735+
}
1736+
}
1737+
}
1738+
1739+
struct TestAsyncLetInStruct {
17301740
func bar() -> Int { 0 }
17311741
func foo() async {
17321742
let _ = {

0 commit comments

Comments
 (0)