]> Cypherpunks repositories - gostls13.git/commitdiff
[dev.typeparams] go/types: better error message for invalid ... use
authorRob Findley <rfindley@google.com>
Thu, 11 Feb 2021 16:46:24 +0000 (11:46 -0500)
committerRobert Findley <rfindley@google.com>
Fri, 12 Feb 2021 15:08:57 +0000 (15:08 +0000)
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>
src/go/types/examples/types.go2
src/go/types/typexpr.go

index 5aa624c13183dd4728a0eb2a7b1d8fa929cae2de..4dba4f0e57d3161eb7a3b50919da9db9d499ac17 100644 (file)
@@ -112,6 +112,9 @@ type I1[T any] interface{
        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.
 type I2 interface {
        I1(int)     // method!
index a6b7314dd527ae2068b686d6aa876470c23178cb..bca0a6664f3ca9c012f11af8c223a933387bc111 100644 (file)
@@ -488,6 +488,12 @@ func (check *Checker) typInternal(e0 ast.Expr, def *Named) (T Type) {
                typ.elem = check.varType(e.Elt)
                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:
                typ := new(Struct)
                def.setUnderlying(typ)