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/parse: confusing error message caused by stray comma in struct field #10579

Open
josharian opened this issue Apr 27, 2015 · 4 comments

Comments

@josharian
Copy link
Contributor

commented Apr 27, 2015

Hit "Format" on http://play.golang.org/p/QX0D-qyFwJ

package main

type T struct {
    a, int
}

Result: "prog.go:4:2: expected anonymous field"

@josharian josharian added this to the Unplanned milestone Apr 27, 2015

@minux

This comment has been minimized.

Copy link
Member

commented Apr 27, 2015

the error produced by gc is not good either.
main.go:4: syntax error: unexpected semicolon or newline

it took me some time to understand why it's complaining
about the newline (it treats int as a field name, and expects
a type)

I think it's pretty hard to generate good diagnostics for this
case due to the ambiguity (it could be a missing field name
or a missing type name).

@mattn

This comment has been minimized.

Copy link
Member

commented Apr 27, 2015

btw, Run says: main.go:4: syntax error: unexpected semicolon or newline

@josharian

This comment has been minimized.

Copy link
Contributor Author

commented Apr 27, 2015

I think it's pretty hard to generate good diagnostics for this case due to the ambiguity (it could be a missing field name or a missing type name).

True, although an error message saying "missing field name or type name" would be better than what we've got.

Not urgent, by any means.

@ianlancetaylor

This comment has been minimized.

Copy link
Contributor

commented Apr 27, 2015

For the record, gccgo says

foo.go:4:11: error: expected type

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
4 participants
You can’t perform that action at this time.