@@ -878,6 +878,13 @@ class Context {
878
878
HandlesErrors(handlesErrors), HandlesAsync(handlesAsync) { }
879
879
880
880
public:
881
+ bool shouldDiagnoseErrorOnTry () const {
882
+ return DiagnoseErrorOnTry;
883
+ }
884
+ void setDiagnoseErrorOnTry (bool b) {
885
+ DiagnoseErrorOnTry = b;
886
+ }
887
+
881
888
// / Whether this is a function that rethrows.
882
889
bool isRethrows () const {
883
890
if (!HandlesErrors)
@@ -1375,6 +1382,7 @@ class CheckEffectsCoverage : public EffectsHandlingWalker<CheckEffectsCoverage>
1375
1382
DeclContext *OldRethrowsDC;
1376
1383
ContextFlags OldFlags;
1377
1384
ThrowingKind OldMaxThrowingKind;
1385
+
1378
1386
public:
1379
1387
ContextScope (CheckEffectsCoverage &self, Optional<Context> newContext)
1380
1388
: Self(self), OldContext(self.CurContext),
@@ -1468,7 +1476,15 @@ class CheckEffectsCoverage : public EffectsHandlingWalker<CheckEffectsCoverage>
1468
1476
}
1469
1477
1470
1478
~ContextScope () {
1479
+ // The "DiagnoseErrorOnTry" flag is a bit of mutable state
1480
+ // in the Context itself, used to postpone diagnostic emission
1481
+ // to a parent "try" expression. If something was diagnosed
1482
+ // during this ContextScope, the flag may have been set, and
1483
+ // we need to preseve its value when restoring the old Context.
1484
+ bool DiagnoseErrorOnTry = Self.CurContext .shouldDiagnoseErrorOnTry ();
1471
1485
Self.CurContext = OldContext;
1486
+ Self.CurContext .setDiagnoseErrorOnTry (DiagnoseErrorOnTry);
1487
+
1472
1488
Self.RethrowsDC = OldRethrowsDC;
1473
1489
Self.Flags = OldFlags;
1474
1490
Self.MaxThrowingKind = OldMaxThrowingKind;
0 commit comments