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

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

Closed
mdempsky opened this issue Feb 27, 2018 · 2 comments

Comments

Projects
None yet
2 participants
@mdempsky
Copy link
Member

commented Feb 27, 2018

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.

@mdempsky mdempsky added the NeedsFix label Feb 27, 2018

@mdempsky

This comment has been minimized.

Copy link
Member Author

commented Feb 27, 2018

The line number for the "previous case" is wrong too. (It's pointing at the constant value declaration, instead of the case clause.)

@gopherbot

This comment has been minimized.

Copy link

commented Mar 3, 2018

Change https://golang.org/cl/98476 mentions this issue: cmd/compile: prevent detection of wrong duplicates

@gopherbot gopherbot closed this in b75e8a2 Mar 7, 2018

@golang golang locked and limited conversation to collaborators Mar 7, 2019

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
You can’t perform that action at this time.