aboutsummaryrefslogtreecommitdiff
path: root/src/go/types/expr.go
diff options
context:
space:
mode:
authorMatthew Dempsky <mdempsky@google.com>2021-04-22 12:42:33 -0700
committerMatthew Dempsky <mdempsky@google.com>2021-04-22 22:01:47 +0000
commit74059685fda0b60d539450ad6b7331ade838e90c (patch)
tree05bdb05c308c68fca17e76de68ec89f4ed20fa26 /src/go/types/expr.go
parentf7afdfd48383c4f0ea8653ea9f8c7b9a3d93abee (diff)
downloadgo-74059685fda0b60d539450ad6b7331ade838e90c.tar.gz
go-74059685fda0b60d539450ad6b7331ade838e90c.zip
go/types: suppress index-out-of-bounds error on Unknown constants
Follow up to CL 312591, which was stumping rfindley and I for a while. Credit to him for figuring out a repro and explaining the correct solution. Change-Id: Ib8578bba05f60fc41d382c34c5266d815441e7a1 Reviewed-on: https://go-review.googlesource.com/c/go/+/312790 Run-TryBot: Matthew Dempsky <mdempsky@google.com> Trust: Matthew Dempsky <mdempsky@google.com> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Robert Findley <rfindley@google.com>
Diffstat (limited to 'src/go/types/expr.go')
-rw-r--r--src/go/types/expr.go11
1 files changed, 8 insertions, 3 deletions
diff --git a/src/go/types/expr.go b/src/go/types/expr.go
index b4eea229b8..4023362a4e 100644
--- a/src/go/types/expr.go
+++ b/src/go/types/expr.go
@@ -1020,9 +1020,14 @@ func (check *Checker) index(index ast.Expr, max int64) (typ Type, val int64) {
return x.typ, -1
}
- v, valid := constant.Int64Val(constant.ToInt(x.val))
- if !valid || max >= 0 && v >= max {
- check.errorf(&x, _InvalidIndex, "index %s is out of bounds", &x)
+ if x.val.Kind() == constant.Unknown {
+ return
+ }
+
+ v, ok := constant.Int64Val(x.val)
+ assert(ok)
+ if max >= 0 && v >= max {
+ check.invalidArg(&x, _InvalidIndex, "index %s is out of bounds", &x)
return
}