Skip to content

Special-case diagnostic for when you just need @unknown default #21695

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 1 commit into from
Jan 8, 2019

Conversation

jrose-apple
Copy link
Contributor

This is a new feature of Swift 5 mode, so it deserves at least a little bit of explanation right in the diagnostic. If you have an otherwise-fully-covered switch but can't assume the enum is frozen, you'll now get this message:

warning: switch covers known cases, but 'MusicGenre' may have additional unknown values

Furthermore, if the enum comes from a system header, it looks like this:

warning: switch covers known cases, but 'NSMusicGenre' may have additional unknown values, possibly added in future versions

...to further suggest the idea that even though your switch is covered now, it might not handle everything in the future. This extra bit is limited to system headers to avoid showing up on C enums defined in your own project, for which it sounds silly. (The main message is still valid though, since you can cram whatever you want into a C enum, and people use this pattern to implement "private cases".)

rdar://problem/39367045

This is a new feature of Swift 5 mode, so it deserves at least a
little bit of explanation right in the diagnostic. If you have an
otherwise-fully-covered switch but can't assume the enum is frozen,
you'll now get this message:

    switch covers known cases, but 'MusicGenre' may have additional
    unknown values

Furthermore, if the enum comes from a system header, it looks like
this:

    switch covers known cases, but 'NSMusicGenre' may have additional
    unknown values, possibly added in future versions

...to further suggest the idea that even though your switch is covered
/now/, it might not handle everything in the /future/. This extra bit
is limited to system headers to avoid showing up on C enums defined in
your own project, for which it sounds silly. (The main message is
still valid though, since you can cram whatever you want into a C
enum, and people use this pattern to implement "private cases".)

rdar://problem/39367045
@jrose-apple
Copy link
Contributor Author

@swift-ci Please test

Copy link
Contributor

@xedin xedin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like new phrasing much better!

Copy link
Contributor

@CodaFi CodaFi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@jrose-apple jrose-apple merged commit 4a8f81d into swiftlang:master Jan 8, 2019
@jrose-apple jrose-apple deleted the into-the-unknown branch January 8, 2019 16:45
jrose-apple added a commit to jrose-apple/swift that referenced this pull request Jan 8, 2019
…iftlang#21695)

This is a new feature of Swift 5 mode, so it deserves at least a
little bit of explanation right in the diagnostic. If you have an
otherwise-fully-covered switch but can't assume the enum is frozen,
you'll now get this message:

    switch covers known cases, but 'MusicGenre' may have additional
    unknown values

Furthermore, if the enum comes from a system header, it looks like
this:

    switch covers known cases, but 'NSMusicGenre' may have additional
    unknown values, possibly added in future versions

...to further suggest the idea that even though your switch is covered
/now/, it might not handle everything in the /future/. This extra bit
is limited to system headers to avoid showing up on C enums defined in
your own project, for which it sounds silly. (The main message is
still valid though, since you can cram whatever you want into a C
enum, and people use this pattern to implement "private cases".)

rdar://problem/39367045
(cherry picked from commit 4a8f81d)
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