go/parser: match syntax parser error for unnamed type parameters

For #54511.

Change-Id: I1ae391b5f157bf688f9f31b1577c90e681b6df26
Reviewed-on: https://go-review.googlesource.com/c/go/+/426655
Reviewed-by: Robert Griesemer <gri@google.com>
Run-TryBot: Robert Griesemer <gri@google.com>
Reviewed-by: Robert Findley <rfindley@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Auto-Submit: Robert Griesemer <gri@google.com>
This commit is contained in:
Robert Griesemer 2022-08-31 14:23:07 -07:00 committed by Gopher Robot
parent d394f99f49
commit 4e32472e79
4 changed files with 9 additions and 10 deletions

View file

@ -897,7 +897,7 @@ func (p *parser) parseParameterList(name0 *ast.Ident, typ0 ast.Expr, closing tok
}
}
if tparams {
p.error(pos, "all type parameters must be named")
p.error(pos, "type parameters must be named")
}
} else if named != len(list) {
// some named => all must be named
@ -925,7 +925,7 @@ func (p *parser) parseParameterList(name0 *ast.Ident, typ0 ast.Expr, closing tok
}
if !ok {
if tparams {
p.error(missingName, "all type parameters must be named")
p.error(missingName, "type parameters must be named")
} else {
p.error(pos, "mixed named and unnamed parameters")
}

View file

@ -196,10 +196,9 @@ var invalids = []string{
`package p; func _[]/* ERROR "empty type parameter list" */()`,
// TODO(rfindley) a better location would be after the ']'
`package p; type _[A /* ERROR "all type parameters must be named" */ ,] struct{ A }`,
`package p; type _[A /* ERROR "type parameters must be named" */ ,] struct{ A }`,
// TODO(rfindley) this error is confusing.
`package p; func _[type /* ERROR "all type parameters must be named" */ P, *Q interface{}]()`,
`package p; func _[type /* ERROR "found 'type'" */ P, *Q interface{}]()`,
`package p; func (T) _[ /* ERROR "must have no type parameters" */ A, B any](a A) B`,
`package p; func (T) _[ /* ERROR "must have no type parameters" */ A, B C](a A) B`,

View file

@ -10,4 +10,4 @@ type _[_ [1]t]t
func _[_ []t]() {}
func _[_ [1]t]() {}
type t [t /* ERROR "all type parameters must be named" */ [0]]t
type t [t /* ERROR "type parameters must be named" */ [0]]t

View file

@ -4,8 +4,8 @@
package p
type _[a /* ERROR "all type parameters must be named" */, b] struct{}
type _[a t, b t, c /* ERROR "all type parameters must be named" */ ] struct{}
type _[a /* ERROR "type parameters must be named" */, b] struct{}
type _[a t, b t, c /* ERROR "type parameters must be named" */ ] struct{}
type _ struct {
t [n]byte
t[a]
@ -18,8 +18,8 @@ type _ interface {
}
func _[] /* ERROR "empty type parameter list" */ ()
func _[a /* ERROR "all type parameters must be named" */, b ]()
func _[a t, b t, c /* ERROR "all type parameters must be named" */ ]()
func _[a /* ERROR "type parameters must be named" */, b ]()
func _[a t, b t, c /* ERROR "type parameters must be named" */ ]()
// TODO(rfindley) incorrect error message (see existing TODO in parser)
func f[a b, 0 /* ERROR "expected '\)', found 0" */ ] ()