Skip to content

Commit bffc743

Browse files
committed
[Concurrency] Make 'await' and 'try' implicit in async let initializer
1 parent 79e6621 commit bffc743

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
@@ -1535,12 +1535,17 @@ class CheckEffectsCoverage : public EffectsHandlingWalker<CheckEffectsCoverage>
15351535
Self.Flags.set(ContextFlags::IsTryCovered);
15361536
Self.Flags.clear(ContextFlags::HasTryThrowSite);
15371537
}
1538-
1538+
15391539
void enterAwait() {
15401540
Self.Flags.set(ContextFlags::IsAsyncCovered);
15411541
Self.Flags.clear(ContextFlags::HasAnyAsyncSite);
15421542
}
15431543

1544+
void enterAsyncLet() {
1545+
Self.Flags.set(ContextFlags::IsTryCovered);
1546+
Self.Flags.set(ContextFlags::IsAsyncCovered);
1547+
}
1548+
15441549
void refineLocalContext(Context newContext) {
15451550
Self.CurContext = newContext;
15461551
}
@@ -1605,7 +1610,7 @@ class CheckEffectsCoverage : public EffectsHandlingWalker<CheckEffectsCoverage>
16051610
OldFlags.mergeFrom(ContextFlags::HasAnyAwait, Self.Flags);
16061611
OldMaxThrowingKind = std::max(OldMaxThrowingKind, Self.MaxThrowingKind);
16071612
}
1608-
1613+
16091614
bool wasTopLevelDebuggerFunction() const {
16101615
return OldFlags.has(ContextFlags::IsTopLevelDebuggerFunction);
16111616
}
@@ -1681,6 +1686,7 @@ class CheckEffectsCoverage : public EffectsHandlingWalker<CheckEffectsCoverage>
16811686

16821687
case AutoClosureExpr::Kind::AsyncLet:
16831688
scope.resetCoverage();
1689+
scope.enterAsyncLet();
16841690
shouldPreserveCoverage = false;
16851691
break;
16861692
}
@@ -1820,10 +1826,11 @@ class CheckEffectsCoverage : public EffectsHandlingWalker<CheckEffectsCoverage>
18201826
}
18211827

18221828
ShouldRecurse_t checkAsyncLet(PatternBindingDecl *patternBinding) {
1823-
// Diagnose async calls in a context that doesn't handle async.
1824-
if (!CurContext.handlesAsync()) {
1825-
CurContext.diagnoseUnhandledAsyncSite(Ctx.Diags, patternBinding);
1826-
}
1829+
// Diagnose async let in a context that doesn't handle async.
1830+
if (!CurContext.handlesAsync()) {
1831+
CurContext.diagnoseUnhandledAsyncSite(Ctx.Diags, patternBinding);
1832+
}
1833+
18271834
return ShouldRecurse;
18281835
}
18291836

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)