Skip to content

Commit bdb25f4

Browse files
committed
[AST] SE-0487: Promote NonexhaustiveAttribute to a language feature
The proposal [has been accepted](https://forums.swift.org/t/accepted-se-0487-nonexhaustive-enums/81508) which makes the feature experimental no longer. (cherry picked from commit a7ecd30)
1 parent 1d65a56 commit bdb25f4

File tree

7 files changed

+13
-38
lines changed

7 files changed

+13
-38
lines changed

include/swift/Basic/Features.def

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -268,6 +268,7 @@ LANGUAGE_FEATURE(BuiltinSelect, 0, "Builtin.select")
268268
LANGUAGE_FEATURE(AlwaysInheritActorContext, 472, "@_inheritActorContext(always)")
269269
LANGUAGE_FEATURE(NonescapableAccessorOnTrivial, 0, "Support UnsafeMutablePointer.mutableSpan")
270270
LANGUAGE_FEATURE(InlineArrayTypeSugar, 483, "Type sugar for InlineArray")
271+
SUPPRESSIBLE_LANGUAGE_FEATURE(NonexhaustiveAttribute, 487, "Nonexhaustive Enums")
271272

272273
// Swift 6
273274
UPCOMING_FEATURE(ConciseMagicFile, 274, 6)
@@ -520,9 +521,6 @@ EXPERIMENTAL_FEATURE(AllowRuntimeSymbolDeclarations, true)
520521
/// Optimize copies of ObjectiveC blocks.
521522
EXPERIMENTAL_FEATURE(CopyBlockOptimization, true)
522523

523-
/// Allow use of `@nonexhaustive` on public enums
524-
SUPPRESSIBLE_EXPERIMENTAL_FEATURE(NonexhaustiveAttribute, false)
525-
526524
/// Allow use of `using` declaration that control default isolation
527525
/// in a file scope.
528526
EXPERIMENTAL_FEATURE(DefaultIsolationPerFile, false)

test/IDE/complete_decl_attribute_feature_requirement.swift

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,14 @@
66
// REQUIRES: asserts
77

88
// RUN: %batch-code-completion -filecheck-additional-suffix _DISABLED
9-
// RUN: %batch-code-completion -filecheck-additional-suffix _ENABLED \
10-
// RUN: -enable-experimental-feature NonexhaustiveAttribute
9+
// RUN: %batch-code-completion -filecheck-additional-suffix _ENABLED
10+
11+
// NOTE: There are currently no experimental features that need code completion
12+
// testing, but this test file is being left in place for when it's needed
13+
// again. At that time, please remove the ABIAttribute tests.
14+
// REQUIRES: new_use_case
1115

1216
// NOTE: Please do not include the ", N items" after "Begin completions". The
1317
// item count creates needless merge conflicts given that an "End completions"
1418
// line exists for each test.
1519

16-
@#^KEYWORD4^# enum E {}
17-
// KEYWORD4: Begin completions
18-
// KEYWORD4_ENABLED-DAG: Keyword/None: nonexhaustive[#{{.*}} Attribute#]; name=nonexhaustive
19-
// KEYWORD4_DISABLED-NOT: Keyword/None: nonexhaustive[#{{.*}} Attribute#]; name=nonexhaustive
20-
// KEYWORD4: End completions

test/IDE/complete_nonexhaustive.swift

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
// RUN: %batch-code-completion -enable-experimental-feature NonexhaustiveAttribute
2-
3-
// REQUIRES: swift_feature_NonexhaustiveAttribute
1+
// RUN: %batch-code-completion
42

53
// NONEXHAUSTIVE-DAG: Keyword/None: warn; name=warn
64

test/ModuleInterface/nonexhaustive_attr.swift

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,8 @@
11
// RUN: %empty-directory(%t)
2-
// RUN: %target-swift-emit-module-interface(%t/Library.swiftinterface) %s -enable-experimental-feature NonexhaustiveAttribute -module-name Library
3-
// RUN: %target-swift-typecheck-module-from-interface(%t/Library.swiftinterface) -enable-experimental-feature NonexhaustiveAttribute -module-name Library
2+
// RUN: %target-swift-emit-module-interface(%t/Library.swiftinterface) %s -module-name Library
43
// RUN: %target-swift-typecheck-module-from-interface(%t/Library.swiftinterface) -module-name Library
54
// RUN: %FileCheck %s < %t/Library.swiftinterface
65

7-
// REQUIRES: swift_feature_NonexhaustiveAttribute
8-
96
// CHECK: #if compiler(>=5.3) && $NonexhaustiveAttribute
107
// CHECK-NEXT: @nonexhaustive public enum E {
118
// CHECK-NEXT: }

test/ModuleInterface/nonexhaustive_enums.swift

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,8 @@
55
/// Build the library
66
// RUN: %target-swift-frontend -emit-module %t/src/Lib.swift \
77
// RUN: -module-name Lib \
8-
// RUN: -emit-module-path %t/Lib.swiftmodule \
9-
// RUN: -enable-experimental-feature NonexhaustiveAttribute
8+
// RUN: -emit-module-path %t/Lib.swiftmodule
109

11-
// Check that the errors are produced when using enums from module with `NonexhaustiveEnums` feature enabled.
1210
// RUN: %target-swift-frontend -typecheck %t/src/TestChecking.swift \
1311
// RUN: -swift-version 5 -module-name Client -I %t \
1412
// RUN: -verify
@@ -19,9 +17,7 @@
1917
// RUN: %target-swift-frontend -emit-module %t/src/Lib.swift \
2018
// RUN: -module-name Lib \
2119
// RUN: -package-name Test \
22-
// RUN: -emit-module-path %t/Lib.swiftmodule \
23-
// RUN: -enable-experimental-feature NonexhaustiveAttribute
24-
20+
// RUN: -emit-module-path %t/Lib.swiftmodule
2521

2622
// Different module but the same package
2723
// RUN: %target-swift-frontend -typecheck %t/src/TestSamePackage.swift \
@@ -34,8 +30,6 @@
3430
// RUN: -swift-version 6 -module-name Client -I %t \
3531
// RUN: -verify
3632

37-
// REQUIRES: swift_feature_NonexhaustiveAttribute
38-
3933
//--- Lib.swift
4034

4135
@nonexhaustive

test/attr/attr_nonexhaustive.swift

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
// RUN: %target-typecheck-verify-swift -enable-experimental-feature NonexhaustiveAttribute
2-
3-
// REQUIRES: swift_feature_NonexhaustiveAttribute
1+
// RUN: %target-typecheck-verify-swift
42

53
@nonexhaustive
64
public enum E1 { // Ok

test/attr/feature_requirement.swift

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// RUN: %target-typecheck-verify-swift -parse-as-library -disable-experimental-parser-round-trip -verify-additional-prefix disabled-
2-
// RUN: %target-typecheck-verify-swift -parse-as-library -verify-additional-prefix enabled- -enable-experimental-feature CompileTimeValues -enable-experimental-feature NonexhaustiveAttribute
2+
// RUN: %target-typecheck-verify-swift -parse-as-library -verify-additional-prefix enabled- -enable-experimental-feature CompileTimeValues
33

44
// REQUIRES: asserts
55

@@ -15,12 +15,3 @@ public let x = 1 // expected-disabled-error@-1 {{'const' attribute is only vali
1515
#error("doesn't have @const") // expected-disabled-error {{doesn't have @const}}
1616
#endif
1717

18-
@nonexhaustive
19-
public enum E {} // expected-disabled-error@-1 {{'nonexhaustive' attribute is only valid when experimental feature NonexhaustiveAttribute is enabled}}
20-
21-
#if hasAttribute(nonexhaustive)
22-
#error("does have @nonexhaustive") // expected-enabled-error {{does have @nonexhaustive}}
23-
#else
24-
#error("doesn't have @nonexhaustive") // expected-disabled-error {{doesn't have @nonexhaustive}}
25-
#endif
26-

0 commit comments

Comments
 (0)