]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/compile/internal/types2: fix incorrect result type of Checker.index
authorRobert Griesemer <gri@golang.org>
Wed, 21 Apr 2021 16:04:00 +0000 (09:04 -0700)
committerRobert Griesemer <gri@golang.org>
Wed, 21 Apr 2021 16:26:01 +0000 (16:26 +0000)
While at it, add missing "invalid argument: " prefix
to a couple of local error messages, for consistency.

For #45667.

Change-Id: I814800b2f3f3750583e335c98a3f8e27030a9daa
Reviewed-on: https://go-review.googlesource.com/c/go/+/312309
Trust: Robert Griesemer <gri@golang.org>
Run-TryBot: Robert Griesemer <gri@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
TryBot-Result: Go Bot <gobot@golang.org>

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

index b9b5b53226105096f72427b7e55f2bd73af7fdb4..6726272f6cc5dcc3e3f8423c28829da45f6ea6a1 100644 (file)
@@ -349,15 +349,15 @@ func (check *Checker) index(index syntax.Expr, max int64) (typ Type, val int64)
        v, valid := constant.Int64Val(constant.ToInt(x.val))
        if !valid || max >= 0 && v >= max {
                if check.conf.CompilerErrorMessages {
-                       check.errorf(&x, "array index %s out of bounds [0:%d]", x.val.String(), max)
+                       check.errorf(&x, invalidArg+"array index %s out of bounds [0:%d]", x.val.String(), max)
                } else {
-                       check.errorf(&x, "index %s is out of bounds", &x)
+                       check.errorf(&x, invalidArg+"index %s is out of bounds", &x)
                }
                return
        }
 
        // 0 <= v [ && v < max ]
-       return Typ[Int], v
+       return x.typ, v
 }
 
 // indexElts checks the elements (elts) of an array or slice composite literal