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: emits invalid ast for Decl with missing type. #9639

barnex opened this issue Jan 19, 2015 · 1 comment

go/parser: emits invalid ast for Decl with missing type. #9639

barnex opened this issue Jan 19, 2015 · 1 comment


Copy link

@barnex barnex commented Jan 19, 2015

The following code
var x;
is invalid and rejected by gc (

However, go/parser parses it without returning an error. Code:

I expected to receive a syntax error like "unexpected semicolon or newline". Instead, no error and an ast containing a Decl with Type nil is emited.

Go version in playground at time of report: go1.3.2
My local go version at time of report: go version devel +1757b5c Thu Dec 11 07:31:32 2014 +0000 linux/amd64

@ianlancetaylor ianlancetaylor added this to the Go1.5 milestone Jan 20, 2015
Copy link

@griesemer griesemer commented Jan 20, 2015

The go/parser deliberately accepts a larger language than what the spec permits, for more lenient parsing which permits better error messages later. If you run through go/types, you will get the error:

$ gotype z.go
z.go:5:9: missing type or init expr
z.go:5:9: x declared but not used

Perhaps in this case the parser could be tightened a bit.

It's trivial to add a verification pass if this is required. This is issue is not urgent.

@griesemer griesemer closed this in dcb37f9 Jan 23, 2015
@golang golang locked and limited conversation to collaborators Jun 25, 2016
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
4 participants
You can’t perform that action at this time.