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

go/types: "duplicate case in expression switch" error could be formatted better (perhaps) #26357

Open
mvdan opened this issue Jul 12, 2018 · 5 comments

Comments

Projects
None yet
3 participants
@mvdan
Copy link
Member

commented Jul 12, 2018

$ go version
go version devel +3df1f00bfc Thu Jul 12 08:22:37 2018 +0000 linux/amd64
$ cd src/go/types
$ go build gotype.go
$ cat f.go
package p

func f(r rune) {
        switch r {
        case 'a':
        case 'a':
        }
}
$ ./gotype f.go
f.go:6:7: duplicate case 'a' (constant 97 of type rune) in expression switch
f.go:5:7:       previous case

Haven't digged into why this error appears to be broken.

/cc @griesemer

@mvdan mvdan added this to the Go1.12 milestone Jul 12, 2018

@mvdan

This comment has been minimized.

Copy link
Member Author

commented Jul 12, 2018

Forgot to mention - the compiler gets this right, as expected:

$ go build f.go
# command-line-arguments
./f.go:6:2: duplicate case 'a' (value 97) in switch
        previous case at ./f.go:5:7
@ianlancetaylor

This comment has been minimized.

Copy link
Contributor

commented Jul 12, 2018

Sorry, I don't understand what you are after here. The go/types error does say "previous case" at f.go:5:7. What should it do instead?

@mvdan

This comment has been minimized.

Copy link
Member Author

commented Jul 12, 2018

Oh, the position is at the left. I completely missed that, even after reading the error multiple times.

Maybe that's just me, or maybe the error could be made clearer. I definitely find the compiler's version easier to understand.

@ianlancetaylor

This comment has been minimized.

Copy link
Contributor

commented Jul 12, 2018

The advantage of putting the position at the left is that it works well with tools, such as editors, which can cycle through the locations. Maybe we can improve the "previous case" text to make that clearer.

@griesemer

This comment has been minimized.

Copy link
Contributor

commented Aug 8, 2018

What @ianlancetaylor said.

@griesemer griesemer modified the milestones: Go1.12, Unplanned Aug 8, 2018

@griesemer griesemer changed the title go/types: missing previous case in "duplicate case in expression switch" error go/types: "duplicate case in expression switch" error could be formatted better (perhaps) Aug 8, 2018

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