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
Labels
FrozenDueToAge NeedsFix The path to resolution is known, but the work has not been done.
Milestone

Comments

@dotaheor
Copy link

dotaheor 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
Copy link
Contributor

bradfitz 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 as completed Feb 2, 2018
@dotaheor
Copy link
Author

dotaheor commented Feb 2, 2018

great!

@griesemer
Copy link
Contributor

@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 The path to resolution is known, but the work has not been done. label Feb 2, 2018
@gopherbot
Copy link

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

@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.
Labels
FrozenDueToAge NeedsFix The path to resolution is known, but the work has not been done.
Projects
None yet
Development

No branches or pull requests

4 participants