Skip to content

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

@mvdan

Description

@mvdan

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions