Skip to content

cmd/compile: regression in type switch deduplication #17517

@dsnet

Description

@dsnet

8c85e23 caused a regression where duplicate cases fail to be detected in a switch.

package main

func main() {
    var a int
    switch a {
    case 0,1:
    case 0:
    }
}

On Go1.7, the above program fails:

./main.go:13: duplicate case 0 in switch
    previous case at ./main.go:12

On Go1.8dev, the above program, unexpectedly succeeds.

I understand that this is not a language guarantee:

Implementation restriction: A compiler may disallow multiple case expressions evaluating to the same constant. For instance, the current compilers disallow duplicate integer, floating point, or string constants in case expressions.

However, we should be consistent with how it is done. The following snippet is rejected on both Go1.7 and Go1.8dev:

var a int
switch a {
case 0:
case 0:
}

/cc @josharian @mdempsky

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

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions