}
}
-func (p *parser) atComma(context string) bool {
+func (p *parser) atComma(context string, follow token.Token) bool {
if p.tok == token.COMMA {
return true
}
- if p.tok == token.SEMICOLON && p.lit == "\n" {
- p.error(p.pos, "missing ',' before newline in "+context)
- return true // "insert" the comma and continue
-
+ if p.tok != follow {
+ msg := "missing ','"
+ if p.tok == token.SEMICOLON && p.lit == "\n" {
+ msg += " before newline"
+ }
+ p.error(p.pos, msg+" in "+context)
+ return true // "insert" comma and continue
}
return false
}
// parameter or result variable is the function body.
p.declare(field, nil, scope, ast.Var, idents...)
p.resolve(typ)
- if !p.atComma("parameter list") {
+ if !p.atComma("parameter list", token.RPAREN) {
return
}
p.next()
// parameter or result variable is the function body.
p.declare(field, nil, scope, ast.Var, idents...)
p.resolve(typ)
- if !p.atComma("parameter list") {
+ if !p.atComma("parameter list", token.RPAREN) {
break
}
p.next()
ellipsis = p.pos
p.next()
}
- if !p.atComma("argument list") {
+ if !p.atComma("argument list", token.RPAREN) {
break
}
p.next()
for p.tok != token.RBRACE && p.tok != token.EOF {
list = append(list, p.parseElement())
- if !p.atComma("composite literal") {
+ if !p.atComma("composite literal", token.RBRACE) {
break
}
p.next()
`package p; func f() { for i /* ERROR "boolean or range expression" */ , x := []string {} }`,
`package p; func f() { go f /* ERROR HERE "function must be invoked" */ }`,
`package p; func f() { defer func() {} /* ERROR HERE "function must be invoked" */ }`,
- `package p; func f() { go func() { func() { f(x func /* ERROR "expected '\)'" */ (){}) } } }`,
- `package p; func f() (a b string /* ERROR "expected '\)'" */ , ok bool)`, // issue 8656
+ `package p; func f() { go func() { func() { f(x func /* ERROR "missing ','" */ (){}) } } }`,
+ `package p; func f(x func(), u v func /* ERROR "missing ','" */ ()){}`,
+ `package p; func f() (a b string /* ERROR "missing ','" */ , ok bool)`, // issue 8656
`package p; var x /* ERROR "missing variable type or initialization" */ , y, z;`, // issue 9639
`package p; const x /* ERROR "missing constant value" */ ;`, // issue 9639
`package p; const x /* ERROR "missing constant value" */ int;`, // issue 9639