From a29437101c5c49841d22c0ee6bf8bcd4c7a5c925 Mon Sep 17 00:00:00 2001 From: Robert Griesemer Date: Thu, 4 Sep 2014 15:18:32 -0700 Subject: [PATCH] go/parser: fix "zero day" parse error (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 | 19 ++++++++++--------- src/pkg/go/parser/short_test.go | 1 + 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/src/pkg/go/parser/parser.go b/src/pkg/go/parser/parser.go index 4d6f36258c..9c62076f25 100644 --- a/src/pkg/go/parser/parser.go +++ b/src/pkg/go/parser/parser.go @@ -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 } diff --git a/src/pkg/go/parser/short_test.go b/src/pkg/go/parser/short_test.go index 8a3c33868b..f861086ddb 100644 --- a/src/pkg/go/parser/short_test.go +++ b/src/pkg/go/parser/short_test.go @@ -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) { -- 2.48.1