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-8891] Issues when checking that a switch is exhaustive #51397

Closed
swift-ci opened this issue Oct 1, 2018 · 2 comments
Closed

[SR-8891] Issues when checking that a switch is exhaustive #51397

swift-ci opened this issue Oct 1, 2018 · 2 comments
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 Oct 1, 2018

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

Xcode 10 public release

Additional Detail from JIRA
Votes 1
Component/s Compiler
Labels Bug
Assignee None
Priority Medium

md5: 98c391b302466107429c1603cf5d9378

duplicates:

  • SR-6316 False-Positive Switch Exhaustiveness Check results in Bad Access / Bad Instruction at Runtime

Issue Description:

The following code compiles even though the switch is not exhaustive. (It is missing a (.eleven, _) case at the bottom).

It also generates a fatal error in certain cases (documented below).

import Foundation


enum Example: Equatable {
    case one
    case two
    case three
    case four
    case five
    case six
    case seven
    case eight
    case nine
    case ten
    case eleven


    static func == (lhs: Example, rhs: Example) -> Bool {
        switch (lhs, rhs) {
        case (.one, .one):
            return true
        case (.two, .two):
            return true
        case (.three, .three):
            return true
        case (.four, .four):
            return true
        case (.five, .five):
            return true
        case (.six, .six):
            return true
        case (.seven, .seven):
            return true
        case (.eight, .eight):
            return true
        case (.nine, .nine):
            return true
        case (.ten, .ten):
            return true
        case (.eleven, .eleven):
            return true
        case (.one, _),
             (.two, _),
             (.three, _),
             (.four, _),
             (.five, _),
             (.six, _),
             (.seven, _),
             (.eight, _),
             (.nine, _),
             (.ten, _):
            return false
        }
    }
}


print(Example.one == Example.eleven) // false (correct)
print(Example.eleven == Example.one) // Thread 1: Fatal error: unexpected enum case while switching on value of type '(Example, Example)'
@belkadan
Copy link
Contributor

belkadan commented Oct 2, 2018

cc @xedin. I think we have one like this already?

@xedin
Copy link
Member

xedin commented Oct 15, 2018

Yes, looks like this is a duplicate of SR-6316

@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

3 participants