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

Closed
mvdan opened this issue Jul 12, 2018 · 7 comments

Comments

@mvdan
Copy link
Member

@mvdan mvdan 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
Copy link
Member Author

@mvdan mvdan 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

Loading

@ianlancetaylor
Copy link
Contributor

@ianlancetaylor ianlancetaylor 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?

Loading

@mvdan
Copy link
Member Author

@mvdan mvdan 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.

Loading

@ianlancetaylor
Copy link
Contributor

@ianlancetaylor ianlancetaylor 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.

Loading

@griesemer
Copy link
Contributor

@griesemer griesemer commented Aug 8, 2018

What @ianlancetaylor said.

Loading

@griesemer griesemer removed this from the Go1.12 milestone Aug 8, 2018
@griesemer griesemer added this to the Unplanned milestone 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
@ALTree
Copy link
Member

@ALTree ALTree commented Sep 14, 2020

Current error message is

test.go:6:7: duplicate case 'a' (value 97) in switch
        previous case at test.go:5:7

So the 2nd line has been clarified, but the position is no longer of the left.

Loading

@griesemer
Copy link
Contributor

@griesemer griesemer commented Sep 25, 2020

I think this ok as is. The 2nd line is really just clarifying the error, it's not another error. Closing as working as intended.

Loading

@griesemer griesemer closed this Sep 25, 2020
@golang golang locked and limited conversation to collaborators Sep 25, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
5 participants