mirror of
https://github.com/golang/go
synced 2024-11-25 08:47:56 -07:00
go/parser: first constant in a constant declaration must have a value
R=r, rsc1 CC=golang-dev https://golang.org/cl/4291042
This commit is contained in:
parent
ec713d68b8
commit
7664ec39b8
@ -1864,10 +1864,10 @@ func (p *parser) parseStmt() (s ast.Stmt) {
|
|||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
// Declarations
|
// Declarations
|
||||||
|
|
||||||
type parseSpecFunction func(p *parser, doc *ast.CommentGroup) ast.Spec
|
type parseSpecFunction func(p *parser, doc *ast.CommentGroup, iota int) ast.Spec
|
||||||
|
|
||||||
|
|
||||||
func parseImportSpec(p *parser, doc *ast.CommentGroup) ast.Spec {
|
func parseImportSpec(p *parser, doc *ast.CommentGroup, _ int) ast.Spec {
|
||||||
if p.trace {
|
if p.trace {
|
||||||
defer un(trace(p, "ImportSpec"))
|
defer un(trace(p, "ImportSpec"))
|
||||||
}
|
}
|
||||||
@ -1894,7 +1894,7 @@ func parseImportSpec(p *parser, doc *ast.CommentGroup) ast.Spec {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
func parseConstSpec(p *parser, doc *ast.CommentGroup) ast.Spec {
|
func parseConstSpec(p *parser, doc *ast.CommentGroup, iota int) ast.Spec {
|
||||||
if p.trace {
|
if p.trace {
|
||||||
defer un(trace(p, "ConstSpec"))
|
defer un(trace(p, "ConstSpec"))
|
||||||
}
|
}
|
||||||
@ -1902,7 +1902,7 @@ func parseConstSpec(p *parser, doc *ast.CommentGroup) ast.Spec {
|
|||||||
idents := p.parseIdentList()
|
idents := p.parseIdentList()
|
||||||
typ := p.tryType()
|
typ := p.tryType()
|
||||||
var values []ast.Expr
|
var values []ast.Expr
|
||||||
if typ != nil || p.tok == token.ASSIGN {
|
if typ != nil || p.tok == token.ASSIGN || iota == 0 {
|
||||||
p.expect(token.ASSIGN)
|
p.expect(token.ASSIGN)
|
||||||
values = p.parseExprList()
|
values = p.parseExprList()
|
||||||
}
|
}
|
||||||
@ -1919,7 +1919,7 @@ func parseConstSpec(p *parser, doc *ast.CommentGroup) ast.Spec {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
func parseTypeSpec(p *parser, doc *ast.CommentGroup) ast.Spec {
|
func parseTypeSpec(p *parser, doc *ast.CommentGroup, _ int) ast.Spec {
|
||||||
if p.trace {
|
if p.trace {
|
||||||
defer un(trace(p, "TypeSpec"))
|
defer un(trace(p, "TypeSpec"))
|
||||||
}
|
}
|
||||||
@ -1939,7 +1939,7 @@ func parseTypeSpec(p *parser, doc *ast.CommentGroup) ast.Spec {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
func parseVarSpec(p *parser, doc *ast.CommentGroup) ast.Spec {
|
func parseVarSpec(p *parser, doc *ast.CommentGroup, _ int) ast.Spec {
|
||||||
if p.trace {
|
if p.trace {
|
||||||
defer un(trace(p, "VarSpec"))
|
defer un(trace(p, "VarSpec"))
|
||||||
}
|
}
|
||||||
@ -1976,13 +1976,13 @@ func (p *parser) parseGenDecl(keyword token.Token, f parseSpecFunction) *ast.Gen
|
|||||||
if p.tok == token.LPAREN {
|
if p.tok == token.LPAREN {
|
||||||
lparen = p.pos
|
lparen = p.pos
|
||||||
p.next()
|
p.next()
|
||||||
for p.tok != token.RPAREN && p.tok != token.EOF {
|
for iota := 0; p.tok != token.RPAREN && p.tok != token.EOF; iota++ {
|
||||||
list = append(list, f(p, p.leadComment))
|
list = append(list, f(p, p.leadComment, iota))
|
||||||
}
|
}
|
||||||
rparen = p.expect(token.RPAREN)
|
rparen = p.expect(token.RPAREN)
|
||||||
p.expectSemi()
|
p.expectSemi()
|
||||||
} else {
|
} else {
|
||||||
list = append(list, f(p, nil))
|
list = append(list, f(p, nil, 0))
|
||||||
}
|
}
|
||||||
|
|
||||||
return &ast.GenDecl{doc, pos, keyword, lparen, list, rparen}
|
return &ast.GenDecl{doc, pos, keyword, lparen, list, rparen}
|
||||||
|
@ -21,6 +21,7 @@ var illegalInputs = []interface{}{
|
|||||||
`package p; func f() { if /* should have condition */ {} };`,
|
`package p; func f() { if /* should have condition */ {} };`,
|
||||||
`package p; func f() { if ; /* should have condition */ {} };`,
|
`package p; func f() { if ; /* should have condition */ {} };`,
|
||||||
`package p; func f() { if f(); /* should have condition */ {} };`,
|
`package p; func f() { if f(); /* should have condition */ {} };`,
|
||||||
|
`package p; const c; /* should have constant value */`,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user