From 58758e0a21c4309f96d44ba24e4c2c9cc12732d9 Mon Sep 17 00:00:00 2001 From: Rob Findley Date: Thu, 11 Feb 2021 11:46:24 -0500 Subject: [PATCH] [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 Trust: Robert Findley Run-TryBot: Robert Findley Reviewed-by: Robert Griesemer --- src/go/types/examples/types.go2 | 3 +++ src/go/types/typexpr.go | 6 ++++++ 2 files changed, 9 insertions(+) diff --git a/src/go/types/examples/types.go2 b/src/go/types/examples/types.go2 index 5aa624c1318..4dba4f0e57d 100644 --- a/src/go/types/examples/types.go2 +++ b/src/go/types/examples/types.go2 @@ -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! diff --git a/src/go/types/typexpr.go b/src/go/types/typexpr.go index a6b7314dd52..bca0a6664f3 100644 --- a/src/go/types/typexpr.go +++ b/src/go/types/typexpr.go @@ -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)