[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 a7ecd309d4)
This commit is contained in:
Pavel Yaskevich
2025-08-20 00:13:34 -07:00
parent 1d65a560d7
commit bdb25f4fec
7 changed files with 13 additions and 38 deletions

View File

@@ -268,6 +268,7 @@ LANGUAGE_FEATURE(BuiltinSelect, 0, "Builtin.select")
LANGUAGE_FEATURE(AlwaysInheritActorContext, 472, "@_inheritActorContext(always)")
LANGUAGE_FEATURE(NonescapableAccessorOnTrivial, 0, "Support UnsafeMutablePointer.mutableSpan")
LANGUAGE_FEATURE(InlineArrayTypeSugar, 483, "Type sugar for InlineArray")
SUPPRESSIBLE_LANGUAGE_FEATURE(NonexhaustiveAttribute, 487, "Nonexhaustive Enums")
// Swift 6
UPCOMING_FEATURE(ConciseMagicFile, 274, 6)
@@ -520,9 +521,6 @@ EXPERIMENTAL_FEATURE(AllowRuntimeSymbolDeclarations, true)
/// Optimize copies of ObjectiveC blocks.
EXPERIMENTAL_FEATURE(CopyBlockOptimization, true)
/// Allow use of `@nonexhaustive` on public enums
SUPPRESSIBLE_EXPERIMENTAL_FEATURE(NonexhaustiveAttribute, false)
/// Allow use of `using` declaration that control default isolation
/// in a file scope.
EXPERIMENTAL_FEATURE(DefaultIsolationPerFile, false)

View File

@@ -6,15 +6,14 @@
// REQUIRES: asserts
// RUN: %batch-code-completion -filecheck-additional-suffix _DISABLED
// RUN: %batch-code-completion -filecheck-additional-suffix _ENABLED \
// RUN: -enable-experimental-feature NonexhaustiveAttribute
// RUN: %batch-code-completion -filecheck-additional-suffix _ENABLED
// NOTE: There are currently no experimental features that need code completion
// testing, but this test file is being left in place for when it's needed
// again. At that time, please remove the ABIAttribute tests.
// REQUIRES: new_use_case
// NOTE: Please do not include the ", N items" after "Begin completions". The
// item count creates needless merge conflicts given that an "End completions"
// line exists for each test.
@#^KEYWORD4^# enum E {}
// KEYWORD4: Begin completions
// KEYWORD4_ENABLED-DAG: Keyword/None: nonexhaustive[#{{.*}} Attribute#]; name=nonexhaustive
// KEYWORD4_DISABLED-NOT: Keyword/None: nonexhaustive[#{{.*}} Attribute#]; name=nonexhaustive
// KEYWORD4: End completions

View File

@@ -1,6 +1,4 @@
// RUN: %batch-code-completion -enable-experimental-feature NonexhaustiveAttribute
// REQUIRES: swift_feature_NonexhaustiveAttribute
// RUN: %batch-code-completion
// NONEXHAUSTIVE-DAG: Keyword/None: warn; name=warn

View File

@@ -1,11 +1,8 @@
// RUN: %empty-directory(%t)
// RUN: %target-swift-emit-module-interface(%t/Library.swiftinterface) %s -enable-experimental-feature NonexhaustiveAttribute -module-name Library
// RUN: %target-swift-typecheck-module-from-interface(%t/Library.swiftinterface) -enable-experimental-feature NonexhaustiveAttribute -module-name Library
// RUN: %target-swift-emit-module-interface(%t/Library.swiftinterface) %s -module-name Library
// RUN: %target-swift-typecheck-module-from-interface(%t/Library.swiftinterface) -module-name Library
// RUN: %FileCheck %s < %t/Library.swiftinterface
// REQUIRES: swift_feature_NonexhaustiveAttribute
// CHECK: #if compiler(>=5.3) && $NonexhaustiveAttribute
// CHECK-NEXT: @nonexhaustive public enum E {
// CHECK-NEXT: }

View File

@@ -5,10 +5,8 @@
/// Build the library
// RUN: %target-swift-frontend -emit-module %t/src/Lib.swift \
// RUN: -module-name Lib \
// RUN: -emit-module-path %t/Lib.swiftmodule \
// RUN: -enable-experimental-feature NonexhaustiveAttribute
// RUN: -emit-module-path %t/Lib.swiftmodule
// Check that the errors are produced when using enums from module with `NonexhaustiveEnums` feature enabled.
// RUN: %target-swift-frontend -typecheck %t/src/TestChecking.swift \
// RUN: -swift-version 5 -module-name Client -I %t \
// RUN: -verify
@@ -19,9 +17,7 @@
// RUN: %target-swift-frontend -emit-module %t/src/Lib.swift \
// RUN: -module-name Lib \
// RUN: -package-name Test \
// RUN: -emit-module-path %t/Lib.swiftmodule \
// RUN: -enable-experimental-feature NonexhaustiveAttribute
// RUN: -emit-module-path %t/Lib.swiftmodule
// Different module but the same package
// RUN: %target-swift-frontend -typecheck %t/src/TestSamePackage.swift \
@@ -34,8 +30,6 @@
// RUN: -swift-version 6 -module-name Client -I %t \
// RUN: -verify
// REQUIRES: swift_feature_NonexhaustiveAttribute
//--- Lib.swift
@nonexhaustive

View File

@@ -1,6 +1,4 @@
// RUN: %target-typecheck-verify-swift -enable-experimental-feature NonexhaustiveAttribute
// REQUIRES: swift_feature_NonexhaustiveAttribute
// RUN: %target-typecheck-verify-swift
@nonexhaustive
public enum E1 { // Ok

View File

@@ -1,5 +1,5 @@
// RUN: %target-typecheck-verify-swift -parse-as-library -disable-experimental-parser-round-trip -verify-additional-prefix disabled-
// RUN: %target-typecheck-verify-swift -parse-as-library -verify-additional-prefix enabled- -enable-experimental-feature CompileTimeValues -enable-experimental-feature NonexhaustiveAttribute
// RUN: %target-typecheck-verify-swift -parse-as-library -verify-additional-prefix enabled- -enable-experimental-feature CompileTimeValues
// REQUIRES: asserts
@@ -15,12 +15,3 @@ public let x = 1 // expected-disabled-error@-1 {{'const' attribute is only vali
#error("doesn't have @const") // expected-disabled-error {{doesn't have @const}}
#endif
@nonexhaustive
public enum E {} // expected-disabled-error@-1 {{'nonexhaustive' attribute is only valid when experimental feature NonexhaustiveAttribute is enabled}}
#if hasAttribute(nonexhaustive)
#error("does have @nonexhaustive") // expected-enabled-error {{does have @nonexhaustive}}
#else
#error("doesn't have @nonexhaustive") // expected-disabled-error {{doesn't have @nonexhaustive}}
#endif