diff options
author | Robert Griesemer <gri@golang.org> | 2015-01-22 21:54:26 -0800 |
---|---|---|
committer | Robert Griesemer <gri@golang.org> | 2015-01-23 17:01:28 +0000 |
commit | dcb37f94e0a981b322f4c15c343695c70cca09d1 (patch) | |
tree | adb65ae87fb0257f29bb0a39cb057862be5e5a3b /src/go/parser/parser.go | |
parent | c242fbc903422b27af2b065e2b90751057349558 (diff) | |
download | go-dcb37f94e0a981b322f4c15c343695c70cca09d1.tar.gz go-dcb37f94e0a981b322f4c15c343695c70cca09d1.zip |
go/parser: report error for var/const decls with missing init exprs
Fixes #9639.
Change-Id: I311045d3df26b29b9380c159ef4727e85650d13b
Reviewed-on: https://go-review.googlesource.com/3211
Reviewed-by: Alan Donovan <adonovan@google.com>
Diffstat (limited to 'src/go/parser/parser.go')
-rw-r--r-- | src/go/parser/parser.go | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/src/go/parser/parser.go b/src/go/parser/parser.go index c9dbd06ad2..0409122c81 100644 --- a/src/go/parser/parser.go +++ b/src/go/parser/parser.go @@ -2228,6 +2228,7 @@ func (p *parser) parseValueSpec(doc *ast.CommentGroup, keyword token.Token, iota defer un(trace(p, keyword.String()+"Spec")) } + pos := p.pos idents := p.parseIdentList() typ := p.tryType() var values []ast.Expr @@ -2238,6 +2239,17 @@ func (p *parser) parseValueSpec(doc *ast.CommentGroup, keyword token.Token, iota } p.expectSemi() // call before accessing p.linecomment + switch keyword { + case token.VAR: + if typ == nil && values == nil { + p.error(pos, "missing variable type or initialization") + } + case token.CONST: + if values == nil && (iota == 0 || typ != nil) { + p.error(pos, "missing constant value") + } + } + // Go spec: The scope of a constant or variable identifier declared inside // a function begins at the end of the ConstSpec or VarSpec and ends at // the end of the innermost containing block. |