mirror of
https://github.com/golang/go
synced 2024-11-11 20:01:37 -07:00
go/types: provide a better error message for [...] array types
This matches types2 behavior. For #54511. Change-Id: Iea906e9fec7e334b7aa7f481de87373fa93d1c7c Reviewed-on: https://go-review.googlesource.com/c/go/+/425715 Reviewed-by: Robert Griesemer <gri@google.com> Run-TryBot: Robert Griesemer <gri@google.com> Auto-Submit: Robert Griesemer <gri@google.com> Reviewed-by: Alan Donovan <adonovan@google.com> TryBot-Result: Gopher Robot <gobot@golang.org>
This commit is contained in:
parent
27006657fa
commit
2eba2ff8a1
2
src/go/types/testdata/check/decls0.go
vendored
2
src/go/types/testdata/check/decls0.go
vendored
@ -51,7 +51,7 @@ func _() { var init int; _ = init }
|
||||
|
||||
// invalid array types
|
||||
type (
|
||||
iA0 [... /* ERROR "invalid use of '...'" */ ]byte
|
||||
iA0 [... /* ERROR "invalid use of \[...\] array" */ ]byte
|
||||
// The error message below could be better. At the moment
|
||||
// we believe an integer that is too large is not an integer.
|
||||
// But at least we get an error.
|
||||
|
@ -292,11 +292,19 @@ func (check *Checker) typInternal(e0 ast.Expr, def *Named) (T Type) {
|
||||
|
||||
typ := new(Array)
|
||||
def.setUnderlying(typ)
|
||||
typ.len = check.arrayLength(e.Len)
|
||||
// Provide a more specific error when encountering a [...] array
|
||||
// rather than leaving it to the handling of the ... expression.
|
||||
if _, ok := e.Len.(*ast.Ellipsis); ok {
|
||||
check.error(e.Len, _BadDotDotDotSyntax, "invalid use of [...] array (outside a composite literal)")
|
||||
typ.len = -1
|
||||
} else {
|
||||
typ.len = check.arrayLength(e.Len)
|
||||
}
|
||||
typ.elem = check.varType(e.Elt)
|
||||
if typ.len >= 0 {
|
||||
return typ
|
||||
}
|
||||
// report error if we encountered [...]
|
||||
|
||||
case *ast.Ellipsis:
|
||||
// dots are handled explicitly where they are legal
|
||||
|
Loading…
Reference in New Issue
Block a user