@@ -2051,6 +2051,9 @@ class CheckEffectsCoverage : public EffectsHandlingWalker<CheckEffectsCoverage>
20512051
20522052 // / Do we have any 'await's in this context?
20532053 HasAnyAwait = 0x80 ,
2054+
2055+ // / Are we in an 'async let' initializer context?
2056+ InAsyncLet = 0x100 ,
20542057 };
20552058 private:
20562059 unsigned Bits;
@@ -2196,8 +2199,7 @@ class CheckEffectsCoverage : public EffectsHandlingWalker<CheckEffectsCoverage>
21962199 }
21972200
21982201 void enterAsyncLet () {
2199- Self.Flags .set (ContextFlags::IsTryCovered);
2200- Self.Flags .set (ContextFlags::IsAsyncCovered);
2202+ Self.Flags .set (ContextFlags::InAsyncLet);
22012203 }
22022204
22032205 void refineLocalContext (Context newContext) {
@@ -2236,6 +2238,11 @@ class CheckEffectsCoverage : public EffectsHandlingWalker<CheckEffectsCoverage>
22362238 // 'async'.
22372239 }
22382240
2241+ void setCoverageForSingleValueStmtExpr () {
2242+ resetCoverage ();
2243+ Self.Flags .mergeFrom (ContextFlags::InAsyncLet, OldFlags);
2244+ }
2245+
22392246 void preserveCoverageFromSingleValueStmtExpr () {
22402247 // We need to preserve whether we saw any throwing sites, to avoid warning
22412248 // on 'do { let x = if .random() { try ... } else { ... } } catch { ... }'
@@ -2393,7 +2400,7 @@ class CheckEffectsCoverage : public EffectsHandlingWalker<CheckEffectsCoverage>
23932400 // For an if/switch expression, we reset coverage such that a 'try'/'await'
23942401 // does not cover the branches.
23952402 ContextScope scope (*this , /* newContext*/ llvm::None);
2396- scope.resetCoverage ();
2403+ scope.setCoverageForSingleValueStmtExpr ();
23972404 SVE->getStmt ()->walk (*this );
23982405 scope.preserveCoverageFromSingleValueStmtExpr ();
23992406 return ShouldNotRecurse;
@@ -2734,7 +2741,8 @@ class CheckEffectsCoverage : public EffectsHandlingWalker<CheckEffectsCoverage>
27342741 classification.getAsyncReason ());
27352742 }
27362743 // Diagnose async calls that are outside of an await context.
2737- else if (!Flags.has (ContextFlags::IsAsyncCovered)) {
2744+ else if (!(Flags.has (ContextFlags::IsAsyncCovered) ||
2745+ Flags.has (ContextFlags::InAsyncLet))) {
27382746 Expr *expr = E.dyn_cast <Expr*>();
27392747 Expr *anchor = walkToAnchor (expr, parentMap,
27402748 CurContext.isWithinInterpolatedString ());
@@ -2770,7 +2778,8 @@ class CheckEffectsCoverage : public EffectsHandlingWalker<CheckEffectsCoverage>
27702778 break ;
27712779
27722780 bool isTryCovered =
2773- (!requiresTry || Flags.has (ContextFlags::IsTryCovered));
2781+ (!requiresTry || Flags.has (ContextFlags::IsTryCovered) ||
2782+ Flags.has (ContextFlags::InAsyncLet));
27742783 if (!CurContext.handlesThrows (throwsKind)) {
27752784 CurContext.diagnoseUnhandledThrowSite (Ctx.Diags , E, isTryCovered,
27762785 classification.getThrowReason ());
0 commit comments