Skip to content

Commit b7be6ce

Browse files
authored
Merge pull request swiftlang#35107 from DougGregor/async-let-implicit-try-await
[Concurrency] Make 'await' and 'try' implicit in async let initializer
2 parents bb705ce + bffc743 commit b7be6ce

File tree

3 files changed

+16
-12
lines changed

3 files changed

+16
-12
lines changed

lib/Sema/TypeCheckEffects.cpp

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1532,12 +1532,17 @@ class CheckEffectsCoverage : public EffectsHandlingWalker<CheckEffectsCoverage>
15321532
Self.Flags.set(ContextFlags::IsTryCovered);
15331533
Self.Flags.clear(ContextFlags::HasTryThrowSite);
15341534
}
1535-
1535+
15361536
void enterAwait() {
15371537
Self.Flags.set(ContextFlags::IsAsyncCovered);
15381538
Self.Flags.clear(ContextFlags::HasAnyAsyncSite);
15391539
}
15401540

1541+
void enterAsyncLet() {
1542+
Self.Flags.set(ContextFlags::IsTryCovered);
1543+
Self.Flags.set(ContextFlags::IsAsyncCovered);
1544+
}
1545+
15411546
void refineLocalContext(Context newContext) {
15421547
Self.CurContext = newContext;
15431548
}
@@ -1602,7 +1607,7 @@ class CheckEffectsCoverage : public EffectsHandlingWalker<CheckEffectsCoverage>
16021607
OldFlags.mergeFrom(ContextFlags::HasAnyAwait, Self.Flags);
16031608
OldMaxThrowingKind = std::max(OldMaxThrowingKind, Self.MaxThrowingKind);
16041609
}
1605-
1610+
16061611
bool wasTopLevelDebuggerFunction() const {
16071612
return OldFlags.has(ContextFlags::IsTopLevelDebuggerFunction);
16081613
}
@@ -1678,6 +1683,7 @@ class CheckEffectsCoverage : public EffectsHandlingWalker<CheckEffectsCoverage>
16781683

16791684
case AutoClosureExpr::Kind::AsyncLet:
16801685
scope.resetCoverage();
1686+
scope.enterAsyncLet();
16811687
shouldPreserveCoverage = false;
16821688
break;
16831689
}
@@ -1817,10 +1823,11 @@ class CheckEffectsCoverage : public EffectsHandlingWalker<CheckEffectsCoverage>
18171823
}
18181824

18191825
ShouldRecurse_t checkAsyncLet(PatternBindingDecl *patternBinding) {
1820-
// Diagnose async calls in a context that doesn't handle async.
1821-
if (!CurContext.handlesAsync()) {
1822-
CurContext.diagnoseUnhandledAsyncSite(Ctx.Diags, patternBinding);
1823-
}
1826+
// Diagnose async let in a context that doesn't handle async.
1827+
if (!CurContext.handlesAsync()) {
1828+
CurContext.diagnoseUnhandledAsyncSite(Ctx.Diags, patternBinding);
1829+
}
1830+
18241831
return ShouldRecurse;
18251832
}
18261833

test/Concurrency/async_let_isolation.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ actor class MyActor {
3030

3131
func outside() async {
3232
let a = MyActor()
33-
async let x = a.synchronous() // expected-error {{call is 'async' in an 'async let' initializer that is not marked with 'await'}}
33+
async let x = a.synchronous() // okay, await is implicit
3434
async let y = await a.synchronous()
3535
_ = await x
3636
_ = await y

test/expr/unary/async_await.swift

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -165,12 +165,9 @@ func testAsyncLet() async throws {
165165
} catch {
166166
}
167167

168-
async let x1 = getIntUnsafely() // expected-error{{call can throw but is not marked with 'try'}}
169-
// expected-note@-1{{did you mean to use 'try'}}
170-
// expected-note@-2{{did you mean to handle error as optional value?}}
171-
// expected-note@-3{{did you mean to disable error propagation?}}
168+
async let x1 = getIntUnsafely() // okay, try is implicit here
172169

173-
async let x2 = getInt() // expected-error{{call is 'async' in an 'async let' initializer that is not marked with 'await'}}
170+
async let x2 = getInt() // okay, await is implicit here
174171

175172
async let x3 = try getIntUnsafely()
176173
async let x4 = try! getIntUnsafely()

0 commit comments

Comments
 (0)