-
Notifications
You must be signed in to change notification settings - Fork 10.5k
[Serialization/TypeChecker] Introduce ExtensibleEnums
feature
#79580
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
Conversation
fb3780d
to
0271c97
Compare
@swift-ci please test |
…um` feature is supported by a module When `ExtensibleEnums` flag is set, it's going to be reflected in the module file produced by the compiler to make sure that consumers know that non-`@frozen` enumerations can gain new cases in the future and switching cannot be exhaustive.
If an enum comes from a different module that has `ExtensibleEnums` feature enabled, unless it requires either `@unknown default:` or `@frozen` because it is allowed to introduce new cases in the future versions of the module.
0271c97
to
b84bf05
Compare
@swift-ci please test |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great stuff!
case .a: break | ||
} | ||
|
||
switch f { // expected-warning {{switch must be exhaustive}} expected-note {{dd missing case: '.b'}} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we add a test that exhaustively switches over f but also has an @unknown default
here. That should generate a warning as well since the default isn't needed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll look into that in a separate PR. Regular exhaustivity rules apply here, so what ever that implementation does is going to be reflected.
switch e { // expected-warning {{switch must be exhaustive}} expected-note {{dd missing case: '.a'}} | ||
@unknown default: break | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we add a test for this
switch e { // expected-warning
case .a: break
@unknown default: break
}
switch f { // expected-warning {{switch must be exhaustive}} expected-note {{dd missing case: '.b'}} | ||
case .a: break | ||
@unknown default: break | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same here can we add a test for this
switch f { // expected-warning
case .a: break
case .b: break
@unknown default: break
Pitch: https://forums.swift.org/t/pitch-extensible-enums-for-non-resilient-modules/77649
Introduced a proposed feature -
ExtensibleEnums
and updates exhaustivity checking toerror if a non-
@frozen
enum that comes from a module that has this feature enabled doesn'thave
@unknown default:
case.