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-4891] Exhaustive switch statement on two optionals is flagged as non-exhaustive #47468

Closed
mikeash opened this issue May 15, 2017 · 3 comments
Assignees
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior.

Comments

@mikeash
Copy link
Contributor

mikeash commented May 15, 2017

Previous ID SR-4891
Radar None
Original Reporter @mikeash
Type Bug
Status Resolved
Resolution Duplicate
Additional Detail from JIRA
Votes 0
Component/s
Labels Bug
Assignee @mikeash
Priority Medium

md5: b57841df53f77b5adcf36e9e90e15f89

duplicates:

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

Issue Description:

This code, which ought to be legal, produces an error:

func f(x: Int?, y: Int?) {
    switch (x, y) {
    case (let x?, _):
        _ = x
        break
    case (_, let y?):
        _ = y
        break
    case (nil, nil):
        break
    }
// switch must be exhaustive, consider adding a default clause
}

I believe the switch is actually exhaustive (the first two cases cover all possibilities where x or y have any non-nil value, and the last case covers the final nil, nil possibility) but the compiler isn't able to detect that.

@jckarter
Copy link
Member

Is this with Xcode 8.x, or with a snapshot? CodaFi (JIRA User) recently fixed this class of bug in master and the 4.0 branch.

@jckarter
Copy link
Member

Just tested with 8.3.2 and master; repros in 8.3.2 but is fixed in master.

@mikeash
Copy link
Contributor Author

mikeash commented May 15, 2017

Oops, sorry, I forgot to specify what I was trying it with. Tested with 8.3.2, plus the 3.1.1 available on BlueMix. Good to hear it's fixed!

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

No branches or pull requests

2 participants