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-1313] Switch statement exhaustiveness not inferred with wildcards and enums #43921

Closed
swift-ci opened this issue Apr 25, 2016 · 1 comment
Assignees
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself type checker Area → compiler: Semantic analysis

Comments

@swift-ci
Copy link
Collaborator

Previous ID SR-1313
Radar None
Original Reporter ashfurrow (JIRA User)
Type Bug
Status Resolved
Resolution Duplicate
Environment

Xcode 7.3 using the stock Swift compiler.

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

md5: 4696a655d484ce39b6ced05a61d40374

duplicates:

  • SR-483 Exhaustivity checking for switch statement with wildcards doesn't work properly

Issue Description:

Bit of a weird issue, let's say we have a two-case enum called Result.

enum Result {
    case Success, Failure
}

And then I have a tuple of two Results. If I switch on the tuple using the following cases, the Swift compiler gives me an error that the switch is not exhaustive.

switch tuple {
case (.Success, .Success): ...
case (_, .Error): ...
case (.Error, _): ...
}

In this simple example it doesn't really matter because I could use a default case, but often I'll have an ErrorType instance associated with the Error case, and I need either one or the other extracted using the case statements. I've solved this in my own code by just using an exhaustive, explicit switch, but as mentioned on Twitter ( https://twitter.com/jckarter/status/724665175018606592 ) this is a bug, as Swift should be able to infer the exhaustiveness.

@CodaFi
Copy link
Member

CodaFi commented Apr 29, 2017

Resolved on master (again) 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 type checker Area → compiler: Semantic analysis
Projects
None yet
Development

No branches or pull requests

2 participants