Skip to content

Commit 1acbf56

Browse files
committed
Sema: Move the fixit for adding missing enum cases to a separate note instead of attaching to the exhaustive error itself.
1 parent 39c550f commit 1acbf56

File tree

2 files changed

+15
-12
lines changed

2 files changed

+15
-12
lines changed

include/swift/AST/DiagnosticsSema.def

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3611,12 +3611,14 @@ WARNING(debug_long_closure_body, none,
36113611
ERROR(empty_switch_stmt,none,
36123612
"'switch' statement body must have at least one 'case' or 'default' "
36133613
"block; do you want to add a default case?",())
3614-
ERROR(non_exhaustive_switch,none,
3615-
"%select{switch must be exhaustive, consider adding |do you want to add }0"
3616-
"%select{missing cases|a default clause}1"
3617-
"%select{:|?}0", (bool, bool))
3614+
ERROR(non_exhaustive_switch,none, "switch must be exhaustive", ())
3615+
NOTE(missing_several_cases,none,
3616+
"do you want to add "
3617+
"%select{missing cases|a default clause}0"
3618+
"?", (bool))
3619+
36183620
NOTE(missing_particular_case,none,
3619-
"missing case: '%0'", (StringRef))
3621+
"add missing case: '%0'", (StringRef))
36203622
WARNING(redundant_particular_case,none,
36213623
"case is already handled by previous patterns; consider removing it",())
36223624

lib/Sema/TypeCheckSwitchStmt.cpp

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -901,9 +901,10 @@ namespace {
901901
Ctx.Diags.diagnose(StartLoc, diag::empty_switch_stmt)
902902
.fixItInsert(EndLoc, Buffer.str());
903903
} else {
904-
Ctx.Diags.diagnose(StartLoc, diag::non_exhaustive_switch,
905-
InEditor, uncovered.isEmpty())
906-
.fixItInsert(EndLoc, Buffer.str());
904+
Ctx.Diags.diagnose(StartLoc, diag::non_exhaustive_switch);
905+
Ctx.Diags.diagnose(StartLoc, diag::missing_several_cases,
906+
uncovered.isEmpty()).fixItInsert(EndLoc,
907+
Buffer.str());
907908
}
908909
return;
909910
}
@@ -938,11 +939,11 @@ namespace {
938939
}
939940
}
940941

941-
Ctx.Diags.diagnose(StartLoc, diag::non_exhaustive_switch, InEditor,
942-
false).fixItInsert(EndLoc, Buffer.str());
942+
Ctx.Diags.diagnose(StartLoc, diag::non_exhaustive_switch),
943+
Ctx.Diags.diagnose(StartLoc, diag::missing_several_cases, false)
944+
.fixItInsert(EndLoc, Buffer.str());
943945
} else {
944-
Ctx.Diags.diagnose(StartLoc, diag::non_exhaustive_switch,
945-
InEditor, false);
946+
Ctx.Diags.diagnose(StartLoc, diag::non_exhaustive_switch);
946947

947948
for (auto &uncoveredSpace : uncovered.getSpaces()) {
948949
SmallVector<Space, 4> flats;

0 commit comments

Comments
 (0)