Skip to content

cmd/compile: spurious "duplicate case in switch" error #24159

Closed
@mdempsky

Description

@mdempsky

This code is spec compliant:

package p

type A int
const X A = 0

func f() {
        type A int
        const Y A = 0

        switch interface{}(nil) {
        case X:
        case Y:
        }
}

go/types and gccgo accept it, but cmd/compile erroneously rejects it with:

a.go:12:2: duplicate case Y (value 0) in switch
        previous case at a.go:4:13

The issue is swt.go:632 is using typeVal to look for value collisions. However, it's using the string representation of types to look for type identity, but this isn't sound as the example above demonstrates.

Metadata

Metadata

Assignees

No one assigned

    Labels

    FrozenDueToAgeNeedsFixThe path to resolution is known, but the work has not been done.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions