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

mvdan opened this issue Nov 5, 2017 · 1 comment

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

mvdan opened this issue Nov 5, 2017 · 1 comment


Copy link

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


What did you do?

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:

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

This comment has been minimized.

Copy link

@gopherbot gopherbot commented Nov 6, 2017

Change mentions this issue: cmd/compile/internal/syntax: better syntax errors for typos in if/switch/for headers

@gopherbot gopherbot closed this in 17ff23f Nov 6, 2017
@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.
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
3 participants
You can’t perform that action at this time.