Skip to content

cmd/vet: check for duplicate cases in switches #15906

Description

@josharian

Consider:

type A [1]int

func f(x A) {
    switch x {
    case A([1]int{1}):
    case A([1]int{1}):
    }
}

This is almost certainly a typo; the second case is unreachable. The compiler may reject duplicate constant cases in expression switches, but not e.g. nil or composite literals containing constants. (See #15896 for discussion.) Perhaps cmd/vet should step in to help catch these likely bugs. This issue is a reminder to investigate.

Metadata

Metadata

Assignees

No one assigned

    Labels

    AnalysisIssues related to static analysis (vet, x/tools/go/analysis)

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions