@@ -878,6 +878,13 @@ class Context {
878878 HandlesErrors(handlesErrors), HandlesAsync(handlesAsync) { }
879879
880880public:
881+ bool shouldDiagnoseErrorOnTry () const {
882+ return DiagnoseErrorOnTry;
883+ }
884+ void setDiagnoseErrorOnTry (bool b) {
885+ DiagnoseErrorOnTry = b;
886+ }
887+
881888 // / Whether this is a function that rethrows.
882889 bool isRethrows () const {
883890 if (!HandlesErrors)
@@ -1375,6 +1382,7 @@ class CheckEffectsCoverage : public EffectsHandlingWalker<CheckEffectsCoverage>
13751382 DeclContext *OldRethrowsDC;
13761383 ContextFlags OldFlags;
13771384 ThrowingKind OldMaxThrowingKind;
1385+
13781386 public:
13791387 ContextScope (CheckEffectsCoverage &self, Optional<Context> newContext)
13801388 : Self(self), OldContext(self.CurContext),
@@ -1468,7 +1476,15 @@ class CheckEffectsCoverage : public EffectsHandlingWalker<CheckEffectsCoverage>
14681476 }
14691477
14701478 ~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 ();
14711485 Self.CurContext = OldContext;
1486+ Self.CurContext .setDiagnoseErrorOnTry (DiagnoseErrorOnTry);
1487+
14721488 Self.RethrowsDC = OldRethrowsDC;
14731489 Self.Flags = OldFlags;
14741490 Self.MaxThrowingKind = OldMaxThrowingKind;
0 commit comments