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-4658] Switch statement with pattern matched tuple incorrectly non-exhaustive #47235

Closed
swift-ci opened this issue Apr 21, 2017 · 3 comments
Closed
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

Previous ID SR-4658
Radar None
Original Reporter keefmoon (JIRA User)
Type Bug
Status Resolved
Resolution Done

Attachment: Download

Environment

Xcode 8.3.2
Swift 3.1

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

md5: 454f3ff04e415555a39c7e1fb36c87d9

Issue Description:

When you have a switch statement that switches on a tuple of enum values, and a pattern of _ is used for a tuple value, depending on its position, the compiler will identify the switch as not being exhaustive, when it is.

Example:

enum State {
    case disabled // No rows
    case awaiting // Input row
    case finished  // Input row + feedback row
}

func updateForState(old oldState: State, new newState: State) {
    
    switch (oldState, newState) {
        
    case (.disabled, .disabled), (.awaiting, .awaiting), (.finished, .finished):
        print("Do nothing")
        
    case (.disabled, _): // Compiler thinks the switch isn't exhaustive
//    case (.disabled, .awaiting), (.disabled, .finished): // If this case is used instead, compiler is happy.
        print("Reload whole section")
        
    case (_, .disabled):
        print("Reload whole section")
        
    case (.awaiting, .finished):
        print("Insert feedback row")
        
    case (.finished, .awaiting):
        print("Remove feedback row")
    }
}

Playground attached to demostrate.

@belkadan
Copy link
Contributor

I suspect we've seen this before, but CodaFi (JIRA User) is reworking this whole area anyway.

@CodaFi
Copy link
Member

CodaFi commented Apr 22, 2017

Yep, my patch handles this just fine.

@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

3 participants