-
Notifications
You must be signed in to change notification settings - Fork 10.5k
[6.2][AST/Sema] SE-0487: Implement @nonexhaustive
attribute and new enum exhaustivity checking rule
#82922
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
+316
−208
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@swift-ci please test |
218aeeb
to
afa6d64
Compare
@swift-ci please test |
@swift-ci please test Windows platform |
This attribute controls whether cross-module access to the declaration needs `@unknown default:` because it's allowed to gain new cases even if the module is non-resilient. (cherry picked from commit a0ae93d)
For now the semantics provided by `@extensible` keyword on per-enum basis. We might return this as an upcoming feature in the future with a way to opt-out. (cherry picked from commit bf19481)
…tribute Guard against condfails when older compilers get a swift interface that uses `@extensible` attribute. The attribute itself doesn't have any effect in swift interfaces yet since all of the public enums are already resilient in that mode. (cherry picked from commit 6d89bca)
(cherry picked from commit 0ad7d8b)
…s for extensible enums Just like `@preconcurrency` for concurrency, this attribute is going to allow exhaustiveness error downgrades for enums that were retroactively marked as `@extensible`. (cherry picked from commit 498430a)
This is an accepted spelling for the attribute. This commit also renames the feature flag from `ExtensibleAttribute` to `NonexhaustiveAttribute` to match the spelling of the attribute. (cherry picked from commit fe1ae75)
…n` argument The spelling `@nonexhaustive(warn)` replaces `@preEnumExtensibility` attriubte. (cherry picked from commit 43eec8f)
(cherry picked from commit 0444d29)
afa6d64
to
1d65a56
Compare
@swift-ci please test |
FranzBusch
reviewed
Aug 19, 2025
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)
@swift-ci please test |
bnbarham
approved these changes
Aug 20, 2025
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Explanation:
This is an implementation of a second revision of SE-0487 proposal to
make non-frozen enums extensible for non-resilient cross-module access.
The new attribute (
@nonexhaustive
) controls whether cross-module accessto the declaration needs
@unknown default:
because it's allowed to gain newcases even if the module is non-resilient. A variant of the flag
@nonexhaustive(warn)
could be used by API authors to push error about non-exhaustive use farther into the
future.
Resolves: rdar://154965992
Main Branch PRs: [AST/Sema] Add
@extensible
attribute onenum
declarations #80503, [Frontend] AddExtensibleAttribute
to guard use of@extensible
at… #81073, [AST/Sema] Add@preEnumExtensibility
attribute to downgrade warning… #81176, [AST/Sema] SE-0487: Adjust implementation based on the LSG feedback #82807Risk: Very Low. These changes are guarded by an experimental feature
NonexhaustiveAttribute
which is not enabled by default yet.Reviewed By: @FranzBusch
Testing: Added new test-cases.