Skip to content

Commit fbbb2bb

Browse files
committed
[Effects handling] Eliminate Context::Kind::NonExhaustiveCatch.
This kind was too specific to error handling; use a bit instead.
1 parent 8083b2d commit fbbb2bb

File tree

1 file changed

+22
-26
lines changed

1 file changed

+22
-26
lines changed

lib/Sema/TypeCheckEffects.cpp

Lines changed: 22 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -816,7 +816,7 @@ class ApplyClassifier {
816816
}
817817
};
818818

819-
/// An error-handling context.
819+
/// An context in which effects might be handled.
820820
class Context {
821821
public:
822822
enum class Kind : uint8_t {
@@ -832,9 +832,6 @@ class Context {
832832
/// A non-throwing autoclosure.
833833
NonThrowingAutoClosure,
834834

835-
/// A non-exhaustive catch within a non-throwing function.
836-
NonExhaustiveCatch,
837-
838835
/// A default argument expression.
839836
DefaultArgument,
840837

@@ -887,6 +884,7 @@ class Context {
887884
}
888885

889886
Kind TheKind;
887+
bool IsNonExhaustiveCatch = false;
890888
bool DiagnoseErrorOnTry = false;
891889
DeclContext *RethrowsDC = nullptr;
892890
InterpolatedStringLiteralExpr *InterpolatedString = nullptr;
@@ -956,10 +954,6 @@ class Context {
956954
return Context(kind);
957955
}
958956

959-
static Context forNonExhaustiveCatch(DoCatchStmt *S) {
960-
return Context(Kind::NonExhaustiveCatch);
961-
}
962-
963957
static Context forCatchPattern(CaseStmt *S) {
964958
return Context(Kind::CatchPattern);
965959
}
@@ -1006,6 +1000,10 @@ class Context {
10061000
return InterpolatedString;
10071001
}
10081002

1003+
void setNonExhaustiveCatch(bool value) {
1004+
IsNonExhaustiveCatch = value;
1005+
}
1006+
10091007
static void diagnoseThrowInIllegalContext(DiagnosticEngine &Diags,
10101008
ASTNode node,
10111009
StringRef description) {
@@ -1103,8 +1101,7 @@ class Context {
11031101
// Allow the diagnostic to fire on the 'try' if we don't have
11041102
// anything else to say.
11051103
if (isTryCovered && !reason.isRethrowsCall() &&
1106-
(getKind() == Kind::NonThrowingFunction ||
1107-
getKind() == Kind::NonExhaustiveCatch)) {
1104+
getKind() == Kind::NonThrowingFunction) {
11081105
DiagnoseErrorOnTry = true;
11091106
return;
11101107
}
@@ -1136,6 +1133,14 @@ class Context {
11361133
return;
11371134

11381135
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+
11391144
diagnoseThrowInLegalContext(Diags, E, isTryCovered, reason,
11401145
diag::throw_in_nonthrowing_function,
11411146
diag::throwing_call_unhandled,
@@ -1149,13 +1154,6 @@ class Context {
11491154
diag::tryless_throwing_call_in_nonthrowing_autoclosure);
11501155
return;
11511156

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-
11591157
case Kind::EnumElementInitializer:
11601158
diagnoseThrowInIllegalContext(Diags, E, "an enum case raw value");
11611159
return;
@@ -1193,14 +1191,12 @@ class Context {
11931191
llvm_unreachable("try is handled!");
11941192

11951193
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+
}
12041200
return;
12051201

12061202
case Kind::NonThrowingAutoClosure:
@@ -1441,7 +1437,7 @@ class CheckEffectsCoverage : public EffectsHandlingWalker<CheckEffectsCoverage>
14411437
// If the enclosing context doesn't handle anything, use a
14421438
// specialized diagnostic about non-exhaustive catches.
14431439
if (CurContext.handlesNothing()) {
1444-
scope.refineLocalContext(Context::forNonExhaustiveCatch(S));
1440+
CurContext.setNonExhaustiveCatch(true);
14451441
}
14461442

14471443
S->getBody()->walk(*this);

0 commit comments

Comments
 (0)