Skip to content

[SR-5279] Compiler reports: "Switch must be exhaustive" but switch is exhaustive #47854

@swift-ci

Description

@swift-ci
Previous ID SR-5279
Radar None
Original Reporter ngocluu (JIRA User)
Type Bug
Status Resolved
Resolution Done
Additional Detail from JIRA
Votes 0
Component/s Compiler
Labels Bug
Assignee None
Priority Medium

md5: b30a833a82198122297db51fd5b0c3da

is duplicated by:

  • SR-5321 Case Exhaustion Check Bug

Issue Description:

Xcode 9 beta 2 (9M137d)

enum Kind {
    case first(a: Int?, b: Int?, c: Int?, d: Int?, e: Int?, f: Bool?)
    case second(a: Int?, b: Int?, c: Int?, d: Int?, e: Bool?)
    
    var name: String {
        switch self {
        case .first:
            return "first"
        case .second:
            return "second"
        }
    }
}

Adding default case shows warning: "Default will never be executed".

Workaround:

var name: String {
    switch self {
    case .first(_):
        return "first"
    case .second(_):
        return "second"
    }
}

This worked in Xcode 9 beta 1.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugA deviation from expected or documented behavior. Also: expected but undesirable behavior.compilerThe Swift compiler itself

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions