@@ -816,7 +816,7 @@ class ApplyClassifier {
816
816
}
817
817
};
818
818
819
- // / An error-handling context.
819
+ // / An context in which effects might be handled .
820
820
class Context {
821
821
public:
822
822
enum class Kind : uint8_t {
@@ -832,9 +832,6 @@ class Context {
832
832
// / A non-throwing autoclosure.
833
833
NonThrowingAutoClosure,
834
834
835
- // / A non-exhaustive catch within a non-throwing function.
836
- NonExhaustiveCatch,
837
-
838
835
// / A default argument expression.
839
836
DefaultArgument,
840
837
@@ -887,6 +884,7 @@ class Context {
887
884
}
888
885
889
886
Kind TheKind;
887
+ bool IsNonExhaustiveCatch = false ;
890
888
bool DiagnoseErrorOnTry = false ;
891
889
DeclContext *RethrowsDC = nullptr ;
892
890
InterpolatedStringLiteralExpr *InterpolatedString = nullptr ;
@@ -956,10 +954,6 @@ class Context {
956
954
return Context (kind);
957
955
}
958
956
959
- static Context forNonExhaustiveCatch (DoCatchStmt *S) {
960
- return Context (Kind::NonExhaustiveCatch);
961
- }
962
-
963
957
static Context forCatchPattern (CaseStmt *S) {
964
958
return Context (Kind::CatchPattern);
965
959
}
@@ -1006,6 +1000,10 @@ class Context {
1006
1000
return InterpolatedString;
1007
1001
}
1008
1002
1003
+ void setNonExhaustiveCatch (bool value) {
1004
+ IsNonExhaustiveCatch = value;
1005
+ }
1006
+
1009
1007
static void diagnoseThrowInIllegalContext (DiagnosticEngine &Diags,
1010
1008
ASTNode node,
1011
1009
StringRef description) {
@@ -1103,8 +1101,7 @@ class Context {
1103
1101
// Allow the diagnostic to fire on the 'try' if we don't have
1104
1102
// anything else to say.
1105
1103
if (isTryCovered && !reason.isRethrowsCall () &&
1106
- (getKind () == Kind::NonThrowingFunction ||
1107
- getKind () == Kind::NonExhaustiveCatch)) {
1104
+ getKind () == Kind::NonThrowingFunction) {
1108
1105
DiagnoseErrorOnTry = true ;
1109
1106
return ;
1110
1107
}
@@ -1136,6 +1133,14 @@ class Context {
1136
1133
return ;
1137
1134
1138
1135
case Kind::NonThrowingFunction:
1136
+ if (IsNonExhaustiveCatch) {
1137
+ diagnoseThrowInLegalContext (Diags, E, isTryCovered, reason,
1138
+ diag::throw_in_nonexhaustive_catch,
1139
+ diag::throwing_call_in_nonexhaustive_catch,
1140
+ diag::tryless_throwing_call_in_nonexhaustive_catch);
1141
+ return ;
1142
+ }
1143
+
1139
1144
diagnoseThrowInLegalContext (Diags, E, isTryCovered, reason,
1140
1145
diag::throw_in_nonthrowing_function,
1141
1146
diag::throwing_call_unhandled,
@@ -1149,13 +1154,6 @@ class Context {
1149
1154
diag::tryless_throwing_call_in_nonthrowing_autoclosure);
1150
1155
return ;
1151
1156
1152
- case Kind::NonExhaustiveCatch:
1153
- diagnoseThrowInLegalContext (Diags, E, isTryCovered, reason,
1154
- diag::throw_in_nonexhaustive_catch,
1155
- diag::throwing_call_in_nonexhaustive_catch,
1156
- diag::tryless_throwing_call_in_nonexhaustive_catch);
1157
- return ;
1158
-
1159
1157
case Kind::EnumElementInitializer:
1160
1158
diagnoseThrowInIllegalContext (Diags, E, " an enum case raw value" );
1161
1159
return ;
@@ -1193,14 +1191,12 @@ class Context {
1193
1191
llvm_unreachable (" try is handled!" );
1194
1192
1195
1193
case Kind::NonThrowingFunction:
1196
- if (DiagnoseErrorOnTry)
1197
- Diags.diagnose (E->getTryLoc (), diag::try_unhandled);
1198
- return ;
1199
-
1200
- case Kind::NonExhaustiveCatch:
1201
- if (DiagnoseErrorOnTry)
1202
- Diags.diagnose (E->getTryLoc (),
1203
- diag::try_unhandled_in_nonexhaustive_catch);
1194
+ if (DiagnoseErrorOnTry) {
1195
+ Diags.diagnose (
1196
+ E->getTryLoc (),
1197
+ IsNonExhaustiveCatch ? diag::try_unhandled_in_nonexhaustive_catch
1198
+ : diag::try_unhandled);
1199
+ }
1204
1200
return ;
1205
1201
1206
1202
case Kind::NonThrowingAutoClosure:
@@ -1441,7 +1437,7 @@ class CheckEffectsCoverage : public EffectsHandlingWalker<CheckEffectsCoverage>
1441
1437
// If the enclosing context doesn't handle anything, use a
1442
1438
// specialized diagnostic about non-exhaustive catches.
1443
1439
if (CurContext.handlesNothing ()) {
1444
- scope. refineLocalContext ( Context::forNonExhaustiveCatch (S) );
1440
+ CurContext. setNonExhaustiveCatch ( true );
1445
1441
}
1446
1442
1447
1443
S->getBody ()->walk (*this );
0 commit comments