Skip to content

Commit 665992b

Browse files
griesemergopherbot
authored andcommitted
go/types, types2: better error for generic type decl. with missing constraint
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 <[email protected]> TryBot-Result: Gopher Robot <[email protected]> Reviewed-by: Robert Griesemer <[email protected]> Reviewed-by: Robert Findley <[email protected]> Auto-Submit: Robert Griesemer <[email protected]>
1 parent 213504e commit 665992b

File tree

3 files changed

+3
-3
lines changed

3 files changed

+3
-3
lines changed

src/cmd/compile/internal/types2/typexpr.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -478,7 +478,7 @@ func (check *Checker) arrayLength(e syntax.Expr) int64 {
478478
if name, _ := e.(*syntax.Name); name != nil {
479479
obj := check.lookup(name.Value)
480480
if obj == nil {
481-
check.errorf(name, _InvalidArrayLen, "undefined %s for array length", name.Value)
481+
check.errorf(name, _InvalidArrayLen, "undefined array length %s or missing type constraint", name.Value)
482482
return -1
483483
}
484484
if _, ok := obj.(*Const); !ok {

src/go/types/typexpr.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -469,7 +469,7 @@ func (check *Checker) arrayLength(e ast.Expr) int64 {
469469
if name, _ := e.(*ast.Ident); name != nil {
470470
obj := check.lookup(name.Name)
471471
if obj == nil {
472-
check.errorf(name, _InvalidArrayLen, "undefined %s for array length", name.Name)
472+
check.errorf(name, _InvalidArrayLen, "undefined array length %s or missing type constraint", name.Name)
473473
return -1
474474
}
475475
if _, ok := obj.(*Const); !ok {

src/internal/types/testdata/fixedbugs/issue43527.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ const L = 10
88

99
type (
1010
_ [L]struct{}
11-
_ [A /* ERROR undefined A for array length */ ]struct{}
11+
_ [A /* ERROR undefined array length A or missing type constraint */ ]struct{}
1212
_ [B /* ERROR invalid array length B */ ]struct{}
1313
_[A any] struct{}
1414

0 commit comments

Comments
 (0)