mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00:00
cmd/compile/internal/syntax: make valid type parameter list in presence of errors
Make sure the parser fills in names and types for type parameter lists, even in the case of errors. While at it, adjust some of the test functions to accept generic code and report all syntax errors. Added offending source as test for types2. Fixes #47996. Change-Id: I449bcf5e2cb80fa2a24cdd3945f484bfca218a06 Reviewed-on: https://go-review.googlesource.com/c/go/+/345476 Trust: Robert Griesemer <gri@golang.org> Reviewed-by: Matthew Dempsky <mdempsky@google.com>
This commit is contained in:
parent
d350a66532
commit
2c60a99f72
4 changed files with 11 additions and 14 deletions
|
|
@ -1924,7 +1924,7 @@ func (p *parser) paramList(name *Name, close token, requireNames bool) (list []*
|
|||
}
|
||||
|
||||
// distribute parameter types (len(list) > 0)
|
||||
if named == 0 {
|
||||
if named == 0 && !requireNames {
|
||||
// all unnamed => found names are named types
|
||||
for _, par := range list {
|
||||
if typ := par.Name; typ != nil {
|
||||
|
|
@ -1932,9 +1932,6 @@ func (p *parser) paramList(name *Name, close token, requireNames bool) (list []*
|
|||
par.Name = nil
|
||||
}
|
||||
}
|
||||
if requireNames {
|
||||
p.syntaxErrorAt(list[0].Type.Pos(), "type parameters must be named")
|
||||
}
|
||||
} else if named != len(list) {
|
||||
// some named => all must have names and types
|
||||
var pos Pos // left-most error position (or unknown)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue