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-12627] Exhaustiveness of a switch statement is ill-defined #55071

Open
swift-ci opened this issue Apr 19, 2020 · 1 comment
Open

[SR-12627] Exhaustiveness of a switch statement is ill-defined #55071

swift-ci opened this issue Apr 19, 2020 · 1 comment

Comments

@swift-ci
Copy link
Collaborator

Previous ID SR-12627
Radar rdar://problem/62894508
Original Reporter fxn (JIRA User)
Type Improvement
Additional Detail from JIRA
Votes 0
Component/s
Labels Improvement
Assignee None
Priority Medium

md5: 0e0108912719ea3c1df9d770256405e7

Issue Description:

The documentation of switch says that it must be exhaustive, but what does that mean is not defined in the docs as far as I can tell.

For example, this one is exhaustive:

let n = [-1, 1].randomElement()!

switch n {
case Int.min..<0:
    print("negative")
case 0...Int.max:
    print("non-negative")
}

but it does not compile. Neither does

let n = [-1, 1].randomElement()!

switch n {
case n where n < 0:
    print("negative")
case n where n >= 0:
    print("non-negative")
}

Of course, you can try and add a dummy default if the compiler does not handle that case. But in any case my point is that, formally, ideally, what exhaustive means should be in the language reference.

@beccadax
Copy link
Contributor

beccadax commented May 5, 2020

@swift-ci create

@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
Projects
None yet
Development

No branches or pull requests

2 participants