1
0
mirror of https://github.com/golang/go synced 2024-11-19 22:04:44 -07:00

go/parser: require that '...' parameters are followed by a type

(matching latest syntax changes)

R=r
CC=golang-dev
https://golang.org/cl/1762042
This commit is contained in:
Robert Griesemer 2010-07-09 13:02:32 -07:00
parent 2e00bf9877
commit 7529d32ee1
2 changed files with 7 additions and 3 deletions

View File

@ -593,9 +593,13 @@ func (p *parser) tryParameterType(ellipsisOk bool) ast.Expr {
if ellipsisOk && p.tok == token.ELLIPSIS {
pos := p.pos
p.next()
typ := p.tryType()
typ := p.tryType() // don't use parseType so we can provide better error message
if typ == nil {
p.Error(pos, "'...' parameter is missing type")
typ = &ast.BadExpr{pos}
}
if p.tok != token.RPAREN {
p.Error(pos, "can use '...' for last parameter only")
p.Error(pos, "can use '...' with last parameter type only")
}
return &ast.Ellipsis{pos, typ}
}

View File

@ -36,7 +36,7 @@ var validPrograms = []interface{}{
`package main; func main() { _ = (<-chan int)(x) }` + "\n",
`package main; func main() { _ = (<-chan <-chan int)(x) }` + "\n",
`package main; func f(func() func() func())` + "\n",
`package main; func f(...)` + "\n",
`package main; func f(...T)` + "\n",
`package main; func f(float, ...int)` + "\n",
`package main; type T []int; var a []bool; func f() { if a[T{42}[0]] {} }` + "\n",
`package main; type T []int; func g(int) bool { return true }; func f() { if g(T{42}[0]) {} }` + "\n",