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
Closed

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

mdempsky opened this issue Feb 27, 2018 · 2 comments
Labels
FrozenDueToAge NeedsFix The path to resolution is known, but the work has not been done.

Comments

@mdempsky
Copy link
Member

mdempsky 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 The path to resolution is known, but the work has not been done. label Feb 27, 2018
@mdempsky
Copy link
Member Author

mdempsky 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
Copy link

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

@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.
Labels
FrozenDueToAge NeedsFix The path to resolution is known, but the work has not been done.
Projects
None yet
Development

No branches or pull requests

2 participants