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-7798] Detecting duplicate cases when matching optional values #50337

Open
martinr448 opened this issue May 29, 2018 · 0 comments
Open

[SR-7798] Detecting duplicate cases when matching optional values #50337

martinr448 opened this issue May 29, 2018 · 0 comments
Labels
compiler The Swift compiler in itself improvement

Comments

@martinr448
Copy link

Previous ID SR-7798
Radar None
Original Reporter @martinr448
Type Improvement
Additional Detail from JIRA
Votes 0
Component/s Compiler
Labels Improvement
Assignee None
Priority Medium

md5: a14fa8ad7b92cee9b59d80b0566f8aad

Issue Description:

We can match a optional value against a optional and non-optional expression, but the compiler does not detect “equivalent” cases:

let x: Int? = 1

switch x {
case 1: print("one")
case .some(1): print("some one") // This is never executed.
default: print("default")
}

case .some(1): is never executed, but the compiler does not emit a warning. It would be an improvement if the compiler would emit a “... is already handled by previous pattern ...” warning.

Tested with Xcode 9.3.1, with both the default toolchain and the Swift 4.2 snapshot from May 20, 2018.

Related discussion in the Swift forum: Matching optionals in a switch statement

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
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 improvement
Projects
None yet
Development

No branches or pull requests

1 participant