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: confusing error on if stmt); expr {...} #22581

Closed
mvdan opened this issue Nov 5, 2017 · 1 comment
Closed

cmd/compile: confusing error on if stmt); expr {...} #22581

mvdan opened this issue Nov 5, 2017 · 1 comment
Milestone

Comments

@mvdan
Copy link
Member

mvdan commented Nov 5, 2017

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

go version devel +936b977c17 Sat Nov 4 11:09:49 2017 +0000 linux/amd64

Does this issue reproduce with the latest release?

Yes.

What did you do?

https://play.golang.org/p/XHC8kt5fa2

What did you expect to see?

Something like 6:15: syntax error: unexpected ), expecting }

What did you see instead?

6:15: syntax error: i := foo() used as value

I found this in real code (one too many closing parentheses), and it took me five minutes of trying to figure out what was wrong before I spotted the cause. The error didn't point me at the cause well at all.

Note that if you use the statement directly, the error is better: https://play.golang.org/p/zcnFf5-Te0

Happens with switch stmt); expr too.

I realise that the error is technically correct, but in practice I think it could be improved. For example, if you format the original play link, go/parser gives a better message:

6:5: expected boolean expression, found simple statement (missing parentheses around composite literal?) (and 1 more errors)

Happy to try to work on this if it sounds like a good idea. /cc @mdempsky @griesemer

@mvdan mvdan changed the title cmd/compile: confusing error cmd/compile: confusing error on if stmt); expr {...} Nov 5, 2017
@griesemer griesemer self-assigned this Nov 5, 2017
@griesemer griesemer added this to the Go1.10 milestone Nov 5, 2017
@gopherbot
Copy link

Change https://golang.org/cl/76290 mentions this issue: cmd/compile/internal/syntax: better syntax errors for typos in if/switch/for headers

@golang golang locked and limited conversation to collaborators Nov 6, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants