Commit 7529d32e authored by Robert Griesemer's avatar Robert Griesemer

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

(matching latest syntax changes)

R=r
CC=golang-dev
https://golang.org/cl/1762042
parent 2e00bf98
......@@ -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}
}
......
......@@ -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",
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment