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: for the similar bad codes, the error message for switch-block is not good as for if-block. #23664

Closed
dotaheor opened this issue Feb 2, 2018 · 4 comments

Comments

Projects
None yet
4 participants
@dotaheor
Copy link

commented Feb 2, 2018

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

go version go1.9.2 linux/amd6

Does this issue reproduce with the latest release?

yes

What did you do?

package main

func f() {}

func main() {
	if f() true { // syntax error: unexpected true, expecting { after if clause
	}
	
	switch f() true { // syntax error: missing { after switch clause
	}
}

What did you expect to see?

./a.go:6:9: syntax error: unexpected true, expecting { after if clause
./a.go:9:13: syntax error: unexpected true, expecting { after switch clause

What did you see instead?

./a.go:6:9: syntax error: unexpected true, expecting { after if clause
./a.go:9:13: syntax error: missing { after switch clause
@bradfitz

This comment has been minimized.

Copy link
Member

commented Feb 2, 2018

Actually, this looks fixed with Go 1.10:

./x.go:6:9: syntax error: unexpected true, expecting semicolon or newline
./x.go:9:13: syntax error: unexpected true, expecting semicolon or newline

@bradfitz bradfitz closed this Feb 2, 2018

@dotaheor

This comment has been minimized.

Copy link
Author

commented Feb 2, 2018

great!

@griesemer

This comment has been minimized.

Copy link
Contributor

commented Feb 2, 2018

@bradfitz I'm going to reopen this for Go 1.11. It's true that the error messages are consistent, but they are not good: In both cases, we're (often) not expecting a semicolon (or newline) but the opening '{' of the block. I think this can be improved.

@griesemer griesemer reopened this Feb 2, 2018

@griesemer griesemer added this to the Go1.11 milestone Feb 2, 2018

@griesemer griesemer added the NeedsFix label Feb 2, 2018

@gopherbot

This comment has been minimized.

Copy link

commented Apr 3, 2018

Change https://golang.org/cl/104616 mentions this issue: cmd/compile/internal/syntax: better error message for incorrect if/switch header

@gopherbot gopherbot closed this in 4637699 Apr 3, 2018

@golang golang locked and limited conversation to collaborators Apr 3, 2019

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