Skip to content

[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

Merged
merged 3 commits into from
Feb 25, 2025

Conversation

xedin
Copy link
Contributor

@xedin xedin commented Feb 24, 2025

Pitch: https://forums.swift.org/t/pitch-extensible-enums-for-non-resilient-modules/77649

Introduced a proposed feature - ExtensibleEnums and updates exhaustivity checking to
error if a non-@frozen enum that comes from a module that has this feature enabled doesn't
have @unknown default: case.

@xedin
Copy link
Contributor Author

xedin commented Feb 24, 2025

@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.
@xedin
Copy link
Contributor Author

xedin commented Feb 25, 2025

@swift-ci please test

Copy link
Member

@FranzBusch FranzBusch left a 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'}}
Copy link
Member

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.

Copy link
Contributor Author

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
}

Copy link
Member

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
}
Copy link
Member

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

@xedin xedin merged commit c3b75ee into swiftlang:main Feb 25, 2025
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants