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

go/parser: confusing error message with missing "range" in for loop #7102

Closed
btracey opened this issue Jan 10, 2014 · 7 comments
Closed

go/parser: confusing error message with missing "range" in for loop #7102

btracey opened this issue Jan 10, 2014 · 7 comments
Milestone

Comments

@btracey
Copy link
Contributor

btracey commented Jan 10, 2014

Relevant code:
http://play.golang.org/p/V_0vWTl3KE

Trying to range over anonymous structs but forgetting the range command, 
"for _, test := []struct{ " ...

Hitting "run" produces a  nice error message, 
"prog.go:6: assignment count mismatch: 2 = 1
prog.go:6: i, test := []struct { i int } literal used as value"

However, running format produces a much more cryptic message "6:6: expected
condition, found simple statement".  I get a similar error message running "go
test".
@minux
Copy link
Member

minux commented Jan 10, 2014

Comment 1:

we probably can do better here. leaving to gri.
btw, go test first uses go/parser to parse the source, so it outputs the same
error message as gofmt.

Labels changed: added release-go1.3maybe, repo-main.

Owner changed to @griesemer.

@btracey
Copy link
Contributor Author

btracey commented Jan 10, 2014

Comment 2:

Thanks for the info. Is there a reason that the error messages from gc couldn't or
shouldn't be the same as those from go/parser?

@griesemer
Copy link
Contributor

Comment 3:

The parser is a different tool. The error messages are not synchronized. Some are better
in gc, some are better in go/parser.

@btracey
Copy link
Contributor Author

btracey commented Jan 10, 2014

Comment 4:

To rephrase my question, isn't it a desirable property that they have the same messages?

@griesemer
Copy link
Contributor

Comment 5:

It's desirable but not easily possible. gc is using yacc, the go/parser is parsing in
recursive-descent fashion. That said, this issue is not the right place to discuss this.

@griesemer
Copy link
Contributor

Comment 6:

https://golang.org/cl/56770045

Status changed to Started.

@griesemer
Copy link
Contributor

Comment 7:

This issue was closed by revision 947aaf2.

Status changed to Fixed.

@rsc rsc added this to the Go1.3 milestone Apr 14, 2015
@golang golang locked and limited conversation to collaborators Jun 25, 2016
This issue was closed.
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

5 participants