]> Cypherpunks repositories - gostls13.git/commitdiff
go/parser: fix "zero day" parse error
authorRobert Griesemer <gri@golang.org>
Thu, 4 Sep 2014 22:18:32 +0000 (15:18 -0700)
committerRobert Griesemer <gri@golang.org>
Thu, 4 Sep 2014 22:18:32 +0000 (15:18 -0700)
(a b string, ok bool) is not a valid signature

Fixes #8656.

LGTM=adonovan
R=adonovan
CC=golang-codereviews
https://golang.org/cl/137140043

src/pkg/go/parser/parser.go
src/pkg/go/parser/short_test.go

index 4d6f36258c53fd4533591836437f4ebd41163087..9c62076f25e7504a84cb1a1351c93bd12c24177e 100644 (file)
@@ -823,9 +823,10 @@ func (p *parser) parseParameterList(scope *ast.Scope, ellipsisOk bool) (params [
                // parameter or result variable is the function body.
                p.declare(field, nil, scope, ast.Var, idents...)
                p.resolve(typ)
-               if p.tok == token.COMMA {
-                       p.next()
+               if !p.atComma("parameter list") {
+                       return
                }
+               p.next()
                for p.tok != token.RPAREN && p.tok != token.EOF {
                        idents := p.parseIdentList()
                        typ := p.parseVarType(ellipsisOk)
@@ -840,15 +841,15 @@ func (p *parser) parseParameterList(scope *ast.Scope, ellipsisOk bool) (params [
                        }
                        p.next()
                }
-       } else {
-               // Type { "," Type } (anonymous parameters)
-               params = make([]*ast.Field, len(list))
-               for i, typ := range list {
-                       p.resolve(typ)
-                       params[i] = &ast.Field{Type: typ}
-               }
+               return
        }
 
+       // Type { "," Type } (anonymous parameters)
+       params = make([]*ast.Field, len(list))
+       for i, typ := range list {
+               p.resolve(typ)
+               params[i] = &ast.Field{Type: typ}
+       }
        return
 }
 
index 8a3c33868b71fb4979f9dabe77aabf27a89821e1..f861086ddbe48de970930eb2cc5d67167700cc9c 100644 (file)
@@ -93,6 +93,7 @@ var invalids = []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`,
 }
 
 func TestInvalid(t *testing.T) {