Skip to content

cmd/compile: duplicate swtich case constant bool expressions are accepted by compiler #28357

@zigo101

Description

@zigo101

What version of Go are you using (go version)?

go version go1.11.1 linux/amd64

Does this issue reproduce with the latest release?

yes

What did you do?

package main

func main() {
	switch {
	case true:
	case true: // ok
	}
	
	switch 123 {
	case 1:
	case 1: // duplicate case 1 in switch
	}
	
	switch "abc" {
	case "a":
	case "a": // duplicate case "a" in switch
	}
}

What did you expect to see?

The first switch block should also compile error.

What did you see instead?

Compiler think the first switch block is valid.

BTW, gccgo also think the string switch is valid.

Metadata

Metadata

Assignees

No one assigned

    Labels

    FrozenDueToAgeNeedsInvestigationSomeone must examine and confirm this is a valid issue and not a duplicate of an existing one.

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions