mirror of
https://github.com/golang/go
synced 2024-09-24 03:10:16 -06:00
[dev.typeparams] cmd/compile/internal/types2: better error message for invalid ... use
This partially addresses the issue below: In many (all) cases we want to handle invalid ... use in the parser as a syntax error; but this ensures that we get a decent error if we get here anyway. Updates #43680. Change-Id: I93af43a5f5741d8bc76e7a13c0db75e6edf43111 Reviewed-on: https://go-review.googlesource.com/c/go/+/283475 Trust: Robert Griesemer <gri@golang.org> Reviewed-by: Robert Findley <rfindley@google.com>
This commit is contained in:
parent
ef5285fbd0
commit
67bf62d939
@ -113,6 +113,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!
|
||||
|
@ -1181,7 +1181,7 @@ func (check *Checker) exprInternal(x *operand, e syntax.Expr, hint Type) exprKin
|
||||
check.ident(x, e, nil, false)
|
||||
|
||||
case *syntax.DotsType:
|
||||
// ellipses are handled explicitly where they are legal
|
||||
// dots are handled explicitly where they are legal
|
||||
// (array composite literals and parameter lists)
|
||||
check.error(e, "invalid use of '...'")
|
||||
goto Error
|
||||
|
@ -521,6 +521,12 @@ func (check *Checker) typInternal(e0 syntax.Expr, def *Named) (T Type) {
|
||||
typ.elem = check.varType(e.Elem)
|
||||
return typ
|
||||
|
||||
case *syntax.DotsType:
|
||||
// dots are handled explicitly where they are legal
|
||||
// (array composite literals and parameter lists)
|
||||
check.error(e, "invalid use of '...'")
|
||||
check.use(e.Elem)
|
||||
|
||||
case *syntax.StructType:
|
||||
typ := new(Struct)
|
||||
def.setUnderlying(typ)
|
||||
|
Loading…
Reference in New Issue
Block a user