From 810957b1555358fd22e6dfd75cdceb2117362f91 Mon Sep 17 00:00:00 2001 From: Robert Griesemer Date: Tue, 8 Dec 2020 17:48:39 -0800 Subject: [PATCH] [dev.typeparams] cmd/compile/internal/types2: adjusted array error message for compiler Also: Triaged/adjusted some more test/fixedbugs tests. Change-Id: Idaba1875273d6da6ef82dd8de8edd8daa885d32c Reviewed-on: https://go-review.googlesource.com/c/go/+/276472 Trust: Robert Griesemer Reviewed-by: Robert Findley --- src/cmd/compile/internal/types2/expr.go | 6 +++++- test/fixedbugs/issue6750.go | 2 +- test/fixedbugs/issue6772.go | 4 ++-- test/fixedbugs/issue7129.go | 6 +++--- test/fixedbugs/issue7150.go | 2 +- test/fixedbugs/issue7153.go | 2 +- test/fixedbugs/issue7223.go | 10 +++++----- test/fixedbugs/issue7310.go | 6 +++--- test/run.go | 19 ++++++------------- 9 files changed, 27 insertions(+), 30 deletions(-) diff --git a/src/cmd/compile/internal/types2/expr.go b/src/cmd/compile/internal/types2/expr.go index c68077547e7..bede0c639d4 100644 --- a/src/cmd/compile/internal/types2/expr.go +++ b/src/cmd/compile/internal/types2/expr.go @@ -1039,7 +1039,11 @@ 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 { - check.errorf(&x, "index %s is out of bounds", &x) + if check.conf.CompilerErrorMessages { + check.errorf(&x, "array index %s out of bounds [0:%d]", x.val.String(), max) + } else { + check.errorf(&x, "index %s is out of bounds", &x) + } return } diff --git a/test/fixedbugs/issue6750.go b/test/fixedbugs/issue6750.go index f62a85009c0..fca4e66aafe 100644 --- a/test/fixedbugs/issue6750.go +++ b/test/fixedbugs/issue6750.go @@ -18,5 +18,5 @@ func printmany(nums ...int) { func main() { printmany(1, 2, 3) printmany([]int{1, 2, 3}...) - printmany(1, "abc", []int{2, 3}...) // ERROR "too many arguments in call to printmany\n\thave \(number, string, \.\.\.int\)\n\twant \(...int\)" + printmany(1, "abc", []int{2, 3}...) // ERROR "too many arguments in call( to printmany\n\thave \(number, string, \.\.\.int\)\n\twant \(...int\))?" } diff --git a/test/fixedbugs/issue6772.go b/test/fixedbugs/issue6772.go index 4d0001c870d..cb8d0a11f21 100644 --- a/test/fixedbugs/issue6772.go +++ b/test/fixedbugs/issue6772.go @@ -7,14 +7,14 @@ package p func f1() { - for a, a := range []int{1, 2, 3} { // ERROR "a repeated on left side of :=" + for a, a := range []int{1, 2, 3} { // ERROR "a repeated on left side of :=|a redeclared" println(a) } } func f2() { var a int - for a, a := range []int{1, 2, 3} { // ERROR "a repeated on left side of :=" + for a, a := range []int{1, 2, 3} { // ERROR "a repeated on left side of :=|a redeclared" println(a) } println(a) diff --git a/test/fixedbugs/issue7129.go b/test/fixedbugs/issue7129.go index 2425cbd3439..14fc418150f 100644 --- a/test/fixedbugs/issue7129.go +++ b/test/fixedbugs/issue7129.go @@ -15,7 +15,7 @@ func g() bool { return true } func h(int, int) {} func main() { - f(g()) // ERROR "in argument to f" - f(true) // ERROR "in argument to f" - h(true, true) // ERROR "in argument to h" + f(g()) // ERROR "in argument to f|incompatible type" + f(true) // ERROR "in argument to f|cannot convert" + h(true, true) // ERROR "in argument to h|cannot convert" } diff --git a/test/fixedbugs/issue7150.go b/test/fixedbugs/issue7150.go index 8a8a7d088fc..4bd9de8645f 100644 --- a/test/fixedbugs/issue7150.go +++ b/test/fixedbugs/issue7150.go @@ -9,7 +9,7 @@ package main func main() { - _ = [0]int{-1: 50} // ERROR "index must be non-negative integer constant" + _ = [0]int{-1: 50} // ERROR "index must be non-negative integer constant|must not be negative" _ = [0]int{0: 0} // ERROR "index 0 out of bounds \[0:0\]" _ = [0]int{5: 25} // ERROR "index 5 out of bounds \[0:0\]" _ = [10]int{2: 10, 15: 30} // ERROR "index 15 out of bounds \[0:10\]" diff --git a/test/fixedbugs/issue7153.go b/test/fixedbugs/issue7153.go index 66b1338496f..7a85fb8779c 100644 --- a/test/fixedbugs/issue7153.go +++ b/test/fixedbugs/issue7153.go @@ -8,4 +8,4 @@ package p -var _ = []int{a: true, true} // ERROR "undefined: a" "cannot use true \(type untyped bool\) as type int in slice literal" +var _ = []int{a: true, true} // ERROR "undefined: a" "cannot use true \(type untyped bool\) as type int in slice literal|cannot convert true" diff --git a/test/fixedbugs/issue7223.go b/test/fixedbugs/issue7223.go index 0ec3476403d..c78de287ff6 100644 --- a/test/fixedbugs/issue7223.go +++ b/test/fixedbugs/issue7223.go @@ -12,9 +12,9 @@ const bits2 uint = 10 func main() { _ = make([]byte, 1<