Skip to content

Commit 187903f

Browse files
authored
Merge pull request swiftlang#83823 from xedin/SE-0487-has-been-accepted
[AST] SE-0487: Promote `NonexhaustiveAttribute` to a language feature
2 parents 7c9bd16 + a7ecd30 commit 187903f

File tree

7 files changed

+18
-40
lines changed

7 files changed

+18
-40
lines changed

include/swift/Basic/Features.def

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -275,6 +275,7 @@ BASELINE_LANGUAGE_FEATURE(IsolatedDeinit, 371, "isolated deinit")
275275
LANGUAGE_FEATURE(InlineArrayTypeSugar, 483, "Type sugar for InlineArray")
276276
LANGUAGE_FEATURE(LifetimeDependenceMutableAccessors, 0, "Support mutable accessors returning ~Escapable results")
277277
LANGUAGE_FEATURE(InoutLifetimeDependence, 0, "Support @_lifetime(&)")
278+
SUPPRESSIBLE_LANGUAGE_FEATURE(NonexhaustiveAttribute, 487, "Nonexhaustive Enums")
278279

279280
// Swift 6
280281
UPCOMING_FEATURE(ConciseMagicFile, 274, 6)
@@ -522,9 +523,6 @@ EXPERIMENTAL_FEATURE(AllowRuntimeSymbolDeclarations, true)
522523
/// Allow use of `@cdecl`
523524
EXPERIMENTAL_FEATURE(CDecl, false)
524525

525-
/// Allow use of `@nonexhaustive` on public enums
526-
SUPPRESSIBLE_EXPERIMENTAL_FEATURE(NonexhaustiveAttribute, false)
527-
528526
/// Allow use of `Module::name` syntax
529527
EXPERIMENTAL_FEATURE(ModuleSelector, false)
530528

test/IDE/complete_decl_attribute_feature_requirement.swift

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,15 @@
33
// it's enabled. When a feature becomes non-experimental, move its test cases
44
// into the normal complete_decl_attribute.swift test file.
55

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

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

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: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,13 @@
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 NonexhaustiveAttribute
2+
// RUN: %target-typecheck-verify-swift -parse-as-library -verify-additional-prefix enabled-
33

44
// REQUIRES: asserts
55

6+
// NOTE: There are currently no experimental features that need code completion
7+
// testing, but this test file is being left in place for when it's needed
8+
// again. At that time, please remove the ABIAttribute tests.
9+
// REQUIRES: new_use_case
10+
611
// This test checks whether DECL_ATTR_FEATURE_REQUIREMENT is being applied correctly.
712
// It is expected to need occasional edits as experimental features are stabilized.
813

9-
@nonexhaustive
10-
public enum E {} // expected-disabled-error@-1 {{'nonexhaustive' attribute is only valid when experimental feature NonexhaustiveAttribute is enabled}}
11-
12-
#if hasAttribute(nonexhaustive)
13-
#error("does have @nonexhaustive") // expected-enabled-error {{does have @nonexhaustive}}
14-
#else
15-
#error("doesn't have @nonexhaustive") // expected-disabled-error {{doesn't have @nonexhaustive}}
16-
#endif
17-

0 commit comments

Comments
 (0)