]> Cypherpunks repositories - gostls13.git/commitdiff
go/parser: require that '...' parameters are followed by a type
authorRobert Griesemer <gri@golang.org>
Fri, 9 Jul 2010 20:02:32 +0000 (13:02 -0700)
committerRobert Griesemer <gri@golang.org>
Fri, 9 Jul 2010 20:02:32 +0000 (13:02 -0700)
(matching latest syntax changes)

R=r
CC=golang-dev
https://golang.org/cl/1762042

src/pkg/go/parser/parser.go
src/pkg/go/parser/parser_test.go

index c1914005a986fe06c17a0816067dcaefe152f8bd..56096013c1abd1a12049eb491737c65cc6e98ef1 100644 (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}
        }
index 01327a41d7b5fafd077acd73a96d0996242b9c74..cad93e2d438014b05b0cca9d1fb4668d5db73104 100644 (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",