mirror of https://github.com/golang/go.git
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
This commit is contained in:
parent
f545b05aae
commit
a29437101c
|
|
@ -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
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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) {
|
||||
|
|
|
|||
Loading…
Reference in New Issue