@@ -1424,6 +1424,9 @@ class Context {
1424
1424
DiagnoseErrorOnTry = b;
1425
1425
}
1426
1426
1427
+ // / Stores the location of the innermost await
1428
+ SourceLoc awaitLoc = SourceLoc();
1429
+
1427
1430
// / Whether this is a function that rethrows.
1428
1431
bool hasPolymorphicEffect (EffectKind kind) const {
1429
1432
if (!Function)
@@ -1683,7 +1686,7 @@ class Context {
1683
1686
auto loc = E.getStartLoc ();
1684
1687
SourceLoc insertLoc;
1685
1688
SourceRange highlight;
1686
-
1689
+
1687
1690
// Generate more specific messages in some cases.
1688
1691
if (auto e = dyn_cast_or_null<ApplyExpr>(E.dyn_cast <Expr*>())) {
1689
1692
if (isa<PrefixUnaryExpr>(e) || isa<PostfixUnaryExpr>(e) ||
@@ -1693,7 +1696,7 @@ class Context {
1693
1696
}
1694
1697
insertLoc = loc;
1695
1698
highlight = e->getSourceRange ();
1696
-
1699
+
1697
1700
if (InterpolatedString &&
1698
1701
e->getCalledValue () &&
1699
1702
e->getCalledValue ()->getBaseName () ==
@@ -1702,7 +1705,7 @@ class Context {
1702
1705
insertLoc = InterpolatedString->getLoc ();
1703
1706
}
1704
1707
}
1705
-
1708
+
1706
1709
Diags.diagnose (loc, message).highlight (highlight);
1707
1710
maybeAddRethrowsNote (Diags, loc, reason);
1708
1711
@@ -2115,14 +2118,16 @@ class CheckEffectsCoverage : public EffectsHandlingWalker<CheckEffectsCoverage>
2115
2118
DeclContext *OldReasyncDC;
2116
2119
ContextFlags OldFlags;
2117
2120
ConditionalEffectKind OldMaxThrowingKind;
2121
+ SourceLoc OldAwaitLoc;
2118
2122
2119
2123
public:
2120
2124
ContextScope (CheckEffectsCoverage &self, Optional<Context> newContext)
2121
2125
: Self(self), OldContext(self.CurContext),
2122
2126
OldRethrowsDC (self.RethrowsDC),
2123
2127
OldReasyncDC(self.ReasyncDC),
2124
2128
OldFlags(self.Flags),
2125
- OldMaxThrowingKind(self.MaxThrowingKind) {
2129
+ OldMaxThrowingKind(self.MaxThrowingKind),
2130
+ OldAwaitLoc(self.CurContext.awaitLoc) {
2126
2131
if (newContext) self.CurContext = *newContext;
2127
2132
}
2128
2133
@@ -2140,9 +2145,10 @@ class CheckEffectsCoverage : public EffectsHandlingWalker<CheckEffectsCoverage>
2140
2145
Self.Flags .clear (ContextFlags::HasTryThrowSite);
2141
2146
}
2142
2147
2143
- void enterAwait () {
2148
+ void enterAwait (SourceLoc awaitLoc ) {
2144
2149
Self.Flags .set (ContextFlags::IsAsyncCovered);
2145
2150
Self.Flags .clear (ContextFlags::HasAnyAsyncSite);
2151
+ Self.CurContext .awaitLoc = awaitLoc;
2146
2152
}
2147
2153
2148
2154
void enterAsyncLet () {
@@ -2239,6 +2245,7 @@ class CheckEffectsCoverage : public EffectsHandlingWalker<CheckEffectsCoverage>
2239
2245
Self.ReasyncDC = OldReasyncDC;
2240
2246
Self.Flags = OldFlags;
2241
2247
Self.MaxThrowingKind = OldMaxThrowingKind;
2248
+ Self.CurContext .awaitLoc = OldAwaitLoc;
2242
2249
}
2243
2250
};
2244
2251
@@ -2647,12 +2654,13 @@ class CheckEffectsCoverage : public EffectsHandlingWalker<CheckEffectsCoverage>
2647
2654
break ;
2648
2655
}
2649
2656
}
2657
+
2650
2658
ShouldRecurse_t checkAwait (AwaitExpr *E) {
2651
2659
2652
2660
// Walk the operand.
2653
2661
ContextScope scope (*this , None);
2654
- scope.enterAwait ();
2655
-
2662
+ scope.enterAwait (E-> getAwaitLoc () );
2663
+
2656
2664
E->getSubExpr ()->walk (*this );
2657
2665
2658
2666
// Warn about 'await' expressions that weren't actually needed, unless of
@@ -2665,7 +2673,7 @@ class CheckEffectsCoverage : public EffectsHandlingWalker<CheckEffectsCoverage>
2665
2673
CurContext.diagnoseUnhandledAsyncSite (Ctx.Diags , E, None,
2666
2674
/* forAwait=*/ true );
2667
2675
}
2668
-
2676
+
2669
2677
// Inform the parent of the walk that an 'await' exists here.
2670
2678
scope.preserveCoverageFromAwaitOperand ();
2671
2679
return ShouldNotRecurse;
0 commit comments