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-483] Exhaustivity checking for switch statement with wildcards doesn't work properly #43100

Closed
swift-ci opened this issue Jan 6, 2016 · 2 comments
Assignees
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself

Comments

@swift-ci
Copy link
Collaborator

swift-ci commented Jan 6, 2016

Previous ID SR-483
Radar rdar://problem/19658507
Original Reporter loic (JIRA User)
Type Bug
Status Resolved
Resolution Done
Environment

Apple Swift version 2.2-dev (LLVM 3ebdbb2c7e, Clang f66c5bb67b, Swift 1f2908b)
Target: x86_64-apple-macosx10.9

Additional Detail from JIRA
Votes 2
Component/s Compiler
Labels Bug
Assignee @CodaFi
Priority Medium

md5: 46b2753712c7c2ea13b96fc0d7a94fb7

is duplicated by:

  • SR-1313 Switch statement exhaustiveness not inferred with wildcards and enums
  • SR-4890 Exhaustive switch not treated as exhaustive
  • SR-4891 Exhaustive switch statement on two optionals is flagged as non-exhaustive
  • SR-2221 Compiler should be able to prove coverage for element-wise tuple match in switch

relates to:

  • SR-4822 Exhaustive switch not recognized as such

Issue Description:

The compiler fails to see that this is an exhaustive switch statement:

enum MyEnum {
    case A, B
}
let (e, f) = (MyEnum.A, MyEnum.B)

switch (e, f) {
case (_, .B) : break
case (.B, _) : break
case (.A, .A): break
}

It accepts the following as exhaustive, but fails to warn that the last case will never be executed:

switch (e, f) {
case (_, .B) : break
case (.B, _) : break
case (.A, .A): break
case (.A, .B): break
}

It does not accept the following as exhaustive (same as the one above, except (.A, .A) is now the first case):

switch (e, f) {
case (.A, .A): break
case (_, .B) : break
case (.B, _) : break
case (.A, .B): break
}
@swift-ci
Copy link
Collaborator Author

Comment by Kelan Champagne (JIRA)

I ran into this too. This is a slightly more distilled variation of the example above.

Starting from the same:

enum MyEnum { case A, B }
let (e, f) = (MyEnum.A, MyEnum.B)

This says error: switch must be exhaustive:

switch (e, f) {
case (.A, .A): break
case (.A, .B): break
case (.B, _): break
}

But, if you move that wildcard case to the top, then it works:

switch (e, f) {
case (.B, _): break
case (.A, .A): break
case (.A, .B): break
}

And, as a sanity check, these all work (as expected):

switch (e, f) {
case (.A, .A): break
case (.A, .B): break
case (.B, .A): break
case (.B, .B): break
}

switch (e, f) {
case (_, _): break
}

switch (e, f) {
case (.A, _): break
case (.B, _): break
}

switch (e, f) {
case (_, .A): break
case (_, .B): break
}

@CodaFi
Copy link
Member

CodaFi commented Apr 29, 2017

Resolved on master by #8908.

@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
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself
Projects
None yet
Development

No branches or pull requests

2 participants