1
0
mirror of https://github.com/golang/go synced 2024-11-26 08:17:59 -07:00

[dev.typeparams] go/types: better error message for invalid ... use

This is a port of CL 283475 to go/types.

For #43680

Change-Id: Ida630651247a40e28d405594394476e346354866
Reviewed-on: https://go-review.googlesource.com/c/go/+/291321
TryBot-Result: Go Bot <gobot@golang.org>
Trust: Robert Findley <rfindley@google.com>
Run-TryBot: Robert Findley <rfindley@google.com>
Reviewed-by: Robert Griesemer <gri@golang.org>
This commit is contained in:
Rob Findley 2021-02-11 11:46:24 -05:00 committed by Robert Findley
parent c0aa7bd760
commit 58758e0a21
2 changed files with 9 additions and 0 deletions

View File

@ -112,6 +112,9 @@ type I1[T any] interface{
m1(T) m1(T)
} }
// There is no such thing as a variadic generic type.
type _[T ... /* ERROR invalid use of ... */ interface{}] struct{}
// Generic interfaces may be embedded as one would expect. // Generic interfaces may be embedded as one would expect.
type I2 interface { type I2 interface {
I1(int) // method! I1(int) // method!

View File

@ -488,6 +488,12 @@ func (check *Checker) typInternal(e0 ast.Expr, def *Named) (T Type) {
typ.elem = check.varType(e.Elt) typ.elem = check.varType(e.Elt)
return typ return typ
case *ast.Ellipsis:
// dots are handled explicitly where they are legal
// (array composite literals and parameter lists)
check.error(e, _InvalidDotDotDot, "invalid use of '...'")
check.use(e.Elt)
case *ast.StructType: case *ast.StructType:
typ := new(Struct) typ := new(Struct)
def.setUnderlying(typ) def.setUnderlying(typ)