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

gccgo: confusing error message when encountering invalid .. (dot dot) token #28128

griesemer opened this issue Oct 10, 2018 · 2 comments


Copy link

@griesemer griesemer commented Oct 10, 2018


$ cat y.go
package p

func f(x {}

current gccgo reports the errors:

$ gccgo -c y.go
y.go:3:10: error: expected package
3 | func f(x {}
  |          ^
y.go:3:8: error: invalid named/anonymous mix
3 | func f(x {}
  |        ^

I would have expected an error at the .. as it is not a valid token.

For the reference, cmd/compile reports for the same file:

$ go tool compile y.go
y.go:3:11: syntax error: unexpected ., expecting name

which seems more sensible.

Copy link

@thanm thanm commented Oct 10, 2018

[Not sure what you mean about ".." being an invalid token -- seems like two valid tokens back to back, DOT followed by DOT]

I poked at this a little bit.

What's happening here is that Parse::parameter_list has to guess whether it is parsing a list of just type names, e.g.

func(int, int, float64) (*[]int)

or whether rather a list with parameter names like

func(x int, y int, q float64) (*[]int)

It accepts the identifier "x", then peeks at the next token. Seeing a ".", it decides that this must be a qualified type (e.g. "package.typename") and it proceeds onward from there. It accepts the ".", then tries to look up "x" as a package, which fails -> hence the "expected package" error. This error is issued before we even get to the second dot.

I think it might be possible to get a slightly better error by delaying the package lookup error, however. I'll see what I can come up with.

Copy link
Contributor Author

@griesemer griesemer commented Oct 10, 2018

@thanm You're right; per the spec this should be a DOT followed by a DOT. (The go/scanner consumes the two .'s and reports them as a single INVALID token. That behavior though is probably incorrect, even though it may produce a slightly more informative error message, ironically.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
None yet
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
3 participants