If a generic type declaration is missing a constraint, syntactically
it is an array type declaration with an undefined array length.
Mention the possibility of a missing constraint in the error message
for the undefined array length.
For #56064.
For #55961.
For #51145.
Change-Id: Ic161aeda9ea44faa8aa3bf3e9d62b3b13a95d4c5
Reviewed-on: https://go-review.googlesource.com/c/go/+/439559
Run-TryBot: Robert Griesemer <gri@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Robert Griesemer <gri@google.com>
Reviewed-by: Robert Findley <rfindley@google.com>
Auto-Submit: Robert Griesemer <gri@google.com>
if name, _ := e.(*syntax.Name); name != nil {
obj := check.lookup(name.Value)
if obj == nil {
- check.errorf(name, _InvalidArrayLen, "undefined %s for array length", name.Value)
+ check.errorf(name, _InvalidArrayLen, "undefined array length %s or missing type constraint", name.Value)
return -1
}
if _, ok := obj.(*Const); !ok {
if name, _ := e.(*ast.Ident); name != nil {
obj := check.lookup(name.Name)
if obj == nil {
- check.errorf(name, _InvalidArrayLen, "undefined %s for array length", name.Name)
+ check.errorf(name, _InvalidArrayLen, "undefined array length %s or missing type constraint", name.Name)
return -1
}
if _, ok := obj.(*Const); !ok {
type (
_ [L]struct{}
- _ [A /* ERROR undefined A for array length */ ]struct{}
+ _ [A /* ERROR undefined array length A or missing type constraint */ ]struct{}
_ [B /* ERROR invalid array length B */ ]struct{}
_[A any] struct{}