Skip to content
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

[SR-12063] Swift should warn for switch case '.none' vs '.none?' ambiguity #54499

Closed
keith opened this issue Jan 21, 2020 · 4 comments
Closed
Assignees
Labels
compiler The Swift compiler in itself diagnostics QoI Bug: Diagnostics Quality of Implementation improvement type checker Area → compiler: Semantic analysis

Comments

@keith
Copy link
Collaborator

keith commented Jan 21, 2020

Previous ID SR-12063
Radar None
Original Reporter @keith
Type Improvement
Status Resolved
Resolution Done
Additional Detail from JIRA
Votes 0
Component/s Compiler
Labels Improvement, DiagnosticsQoI, TypeChecker
Assignee @theblixguy
Priority Medium

md5: 17a3bec14e602d0feaaa8c2f85e8aae7

Issue Description:

With this code:

enum Foo {
    case bar
    case none
}

let a: Foo? = Foo.none

switch a {
case .none: // Should be '.none?'
    print(".none")
case .bar:
    print(".bar")
default:
    print("default")
}

Everything compiles, but you may have surprising behavior where the `default` case is matched instead of `case .none`.

Following by the example of the great warning you get when you have `let a: Foo? = .none`, it would be great if there was a similar warning for the "ambiguity" here

@keith
Copy link
Collaborator Author

keith commented Jan 21, 2020

Looks like this concern was brought up on the other PR allowing the removal of the `?` in the first place #22486 (comment)

@theblixguy
Copy link
Collaborator

Good idea, I’ll take a look tomorrow! I think the fix-it should be to change it to 'nil' if you want to match against Optional.none. This is what the official documentation does as well (see https://docs.swift.org/swift-book/ReferenceManual/Patterns.html#ID424).

@theblixguy
Copy link
Collaborator

Fixed by #29356 Please verify using the next available snapshot.

@keith
Copy link
Collaborator Author

keith commented Jan 23, 2020

Thanks!

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
compiler The Swift compiler in itself diagnostics QoI Bug: Diagnostics Quality of Implementation improvement type checker Area → compiler: Semantic analysis
Projects
None yet
Development

No branches or pull requests

2 participants