]> Cypherpunks repositories - gostls13.git/commitdiff
go/types, types2: better index-out-of-bounds error message (cleanup)
authorRobert Griesemer <gri@golang.org>
Mon, 28 Mar 2022 22:30:37 +0000 (15:30 -0700)
committerRobert Griesemer <gri@golang.org>
Tue, 29 Mar 2022 17:21:15 +0000 (17:21 +0000)
Use the 1.17 compiler error message, sans "array" prefix.

Change-Id: I0e70781c5ff02dca30a2004ab4d0ea82b0849eae
Reviewed-on: https://go-review.googlesource.com/c/go/+/396296
Trust: Robert Griesemer <gri@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
src/cmd/compile/internal/types2/index.go
src/go/types/index.go
test/fixedbugs/issue13365.go

index 61009c121eca37c2675960853b032c60cc453d72..37db50333ceba42f52db2bea72f1a0e828845b96 100644 (file)
@@ -368,11 +368,7 @@ func (check *Checker) index(index syntax.Expr, max int64) (typ Type, val int64)
        v, ok := constant.Int64Val(x.val)
        assert(ok)
        if max >= 0 && v >= max {
-               if check.conf.CompilerErrorMessages {
-                       check.errorf(&x, invalidArg+"array index %s out of bounds [0:%d]", x.val.String(), max)
-               } else {
-                       check.errorf(&x, invalidArg+"index %s is out of bounds", &x)
-               }
+               check.errorf(&x, invalidArg+"index %s out of bounds [0:%d]", x.val.String(), max)
                return
        }
 
index 33075edaf14c97d3a10cc0ec811496259eacef44..670c95d6219dce093b3dd55bfe5d10860224ac09 100644 (file)
@@ -365,7 +365,7 @@ func (check *Checker) index(index ast.Expr, max int64) (typ Type, val int64) {
        v, ok := constant.Int64Val(x.val)
        assert(ok)
        if max >= 0 && v >= max {
-               check.invalidArg(&x, _InvalidIndex, "index %s is out of bounds", &x)
+               check.invalidArg(&x, _InvalidIndex, "index %s out of bounds [0:%d]", x.val.String(), max)
                return
        }
 
index b22fa0fb4e576dcb67f56783e31681e8754983a9..02c6e0369844e0d63c92f65e350ad3f99cc9d530 100644 (file)
@@ -16,7 +16,7 @@ func main() {
        _ = [...]int{-1: 0} // ERROR "index must be non\-negative integer constant|index expression is negative|must not be negative"
 
        _ = []int{100: 0}
-       _ = [10]int{100: 0} // ERROR "array index 100 out of bounds|out of range"
+       _ = [10]int{100: 0} // ERROR "index 100 out of bounds|out of range"
        _ = [...]int{100: 0}
 
        _ = []int{t}    // ERROR "cannot use .* as (type )?int( in slice literal)?|incompatible type"