Skip to content

Commit a7920ce

Browse files
committed
[Features] Replace -enable-nonfrozen-enum-exhaustivity-diagnostics with an
upcoming feature. The bespoke flag still works as a way to enable the `NonfrozenEnumExhaustivity` upcoming feature. `NonfrozenEnumExhaustivity` is enabled by default in the Swift 6 language mode as errors, and enabled by default in the Swift 5 language mode as warnings.
1 parent 910bc35 commit a7920ce

File tree

6 files changed

+11
-10
lines changed

6 files changed

+11
-10
lines changed

include/swift/Basic/Features.def

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,7 @@ UPCOMING_FEATURE(InferSendableFromCaptures, 418, 6)
192192
UPCOMING_FEATURE(ImplicitOpenExistentials, 352, 6)
193193
UPCOMING_FEATURE(RegionBasedIsolation, 414, 6)
194194
UPCOMING_FEATURE(DynamicActorIsolation, 423, 6)
195+
UPCOMING_FEATURE(NonfrozenEnumExhaustivity, 192, 6)
195196

196197
// Swift 7
197198
UPCOMING_FEATURE(ExistentialAny, 335, 7)

include/swift/Basic/LangOptions.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -454,10 +454,6 @@ namespace swift {
454454
/// Diagnose uses of NSCoding with classes that have unstable mangled names.
455455
bool EnableNSKeyedArchiverDiagnostics = true;
456456

457-
/// Diagnose switches over non-frozen enums that do not have catch-all
458-
/// cases.
459-
bool EnableNonFrozenEnumExhaustivityDiagnostics = false;
460-
461457
/// Regex for the passes that should report passed and missed optimizations.
462458
///
463459
/// These are shared_ptrs so that this class remains copyable.

lib/AST/FeatureSet.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -653,6 +653,8 @@ static bool usesFeatureTransferringArgsAndResults(Decl *decl) {
653653

654654
UNINTERESTING_FEATURE(DynamicActorIsolation)
655655

656+
UNINTERESTING_FEATURE(NonfrozenEnumExhaustivity)
657+
656658
UNINTERESTING_FEATURE(BorrowingSwitch)
657659

658660
UNINTERESTING_FEATURE(ClosureIsolation)

lib/Frontend/CompilerInvocation.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1084,10 +1084,11 @@ static bool ParseLangArgs(LangOptions &Opts, ArgList &Args,
10841084
OPT_disable_nskeyedarchiver_diagnostics,
10851085
Opts.EnableNSKeyedArchiverDiagnostics);
10861086

1087-
Opts.EnableNonFrozenEnumExhaustivityDiagnostics =
1088-
Args.hasFlag(OPT_enable_nonfrozen_enum_exhaustivity_diagnostics,
1089-
OPT_disable_nonfrozen_enum_exhaustivity_diagnostics,
1090-
Opts.isSwiftVersionAtLeast(5));
1087+
if (Args.hasFlag(OPT_enable_nonfrozen_enum_exhaustivity_diagnostics,
1088+
OPT_disable_nonfrozen_enum_exhaustivity_diagnostics,
1089+
Opts.isSwiftVersionAtLeast(5))) {
1090+
Opts.enableFeature(Feature::NonfrozenEnumExhaustivity);
1091+
}
10911092

10921093
if (Arg *A = Args.getLastArg(OPT_Rpass_EQ))
10931094
Opts.OptimizationRemarkPassedPattern =

lib/Sema/TypeCheckSwitchStmt.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1157,7 +1157,7 @@ namespace {
11571157
case DowngradeToWarning::ForUnknownCase: {
11581158
if (Context.LangOpts.DebuggerSupport ||
11591159
Context.LangOpts.Playground ||
1160-
!Context.LangOpts.EnableNonFrozenEnumExhaustivityDiagnostics) {
1160+
!Context.LangOpts.hasFeature(Feature::NonfrozenEnumExhaustivity)) {
11611161
// Don't require covering unknown cases in the debugger or in
11621162
// playgrounds.
11631163
return;
@@ -1259,7 +1259,7 @@ namespace {
12591259
// will later decompose the space into cases.
12601260
continue;
12611261
}
1262-
if (!Context.LangOpts.EnableNonFrozenEnumExhaustivityDiagnostics)
1262+
if (!Context.LangOpts.hasFeature(Feature::NonfrozenEnumExhaustivity))
12631263
continue;
12641264

12651265
// This can occur if the switch is empty and the subject type is an

test/Sema/exhaustive_switch.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// RUN: %target-swift-frontend -swift-version 5 -enable-library-evolution %S/Inputs/exhaustive_switch_testable_helper.swift -emit-module -o %t
33
// RUN: %target-typecheck-verify-swift -swift-version 5 -enable-library-evolution -I %t
44
// RUN: %target-typecheck-verify-swift -swift-version 4 -enable-library-evolution -enable-nonfrozen-enum-exhaustivity-diagnostics -I %t
5+
// RUN: %target-typecheck-verify-swift -swift-version 4 -enable-library-evolution -enable-upcoming-feature NonfrozenEnumExhaustivity -I %t
56

67
import exhaustive_switch_testable_helper
78

0 commit comments

Comments
 (0)