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
Open
Milestone

Comments

@josharian
Copy link
Contributor

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
Copy link
Member

minux 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
Copy link
Member

mattn commented Apr 27, 2015

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

@josharian
Copy link
Contributor Author

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
Copy link
Contributor

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
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants