aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorRobert Griesemer <gri@golang.org>2014-09-04 15:18:32 -0700
committerRobert Griesemer <gri@golang.org>2014-09-04 15:18:32 -0700
commita29437101c5c49841d22c0ee6bf8bcd4c7a5c925 (patch)
tree1ba8e333aafdc5b3642ac1157d9f989597d1b04b /src
parentf545b05aaec2d13e664ce48ce2c258bcfce307c4 (diff)
downloadgo-a29437101c5c49841d22c0ee6bf8bcd4c7a5c925.tar.xz
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
Diffstat (limited to 'src')
-rw-r--r--src/pkg/go/parser/parser.go19
-rw-r--r--src/pkg/go/parser/short_test.go1
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) {