1
0
mirror of https://github.com/golang/go synced 2024-11-26 05:07:59 -07:00

[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 <gri@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
This commit is contained in:
Robert Griesemer 2020-12-08 17:48:39 -08:00
parent c32566c336
commit 810957b155
9 changed files with 27 additions and 30 deletions

View File

@ -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
}

View File

@ -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\))?"
}

View File

@ -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)

View File

@ -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"
}

View File

@ -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\]"

View File

@ -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"

View File

@ -12,9 +12,9 @@ const bits2 uint = 10
func main() {
_ = make([]byte, 1<<bits1)
_ = make([]byte, 1<<bits2)
_ = make([]byte, nil) // ERROR "non-integer.*len"
_ = make([]byte, nil, 2) // ERROR "non-integer.*len"
_ = make([]byte, 1, nil) // ERROR "non-integer.*cap"
_ = make([]byte, true) // ERROR "non-integer.*len"
_ = make([]byte, "abc") // ERROR "non-integer.*len"
_ = make([]byte, nil) // ERROR "non-integer.*len|untyped nil"
_ = make([]byte, nil, 2) // ERROR "non-integer.*len|untyped nil"
_ = make([]byte, 1, nil) // ERROR "non-integer.*cap|untyped nil"
_ = make([]byte, true) // ERROR "non-integer.*len|untyped bool"
_ = make([]byte, "abc") // ERROR "non-integer.*len|untyped string"
}

View File

@ -9,7 +9,7 @@
package main
func main() {
_ = copy(nil, []int{}) // ERROR "use of untyped nil"
_ = copy([]int{}, nil) // ERROR "use of untyped nil"
_ = 1 + true // ERROR "mismatched types untyped int and untyped bool"
_ = copy(nil, []int{}) // ERROR "use of untyped nil|untyped nil"
_ = copy([]int{}, nil) // ERROR "use of untyped nil|untyped nil"
_ = 1 + true // ERROR "mismatched types untyped int and untyped bool|untyped int .* untyped bool"
}

View File

@ -2115,19 +2115,12 @@ var excluded = map[string]bool{
"fixedbugs/issue6703x.go": true,
"fixedbugs/issue6703y.go": true,
"fixedbugs/issue6703z.go": true,
"fixedbugs/issue6750.go": true,
"fixedbugs/issue6772.go": true,
"fixedbugs/issue6889.go": true,
"fixedbugs/issue7129.go": true,
"fixedbugs/issue7150.go": true,
"fixedbugs/issue7153.go": true,
"fixedbugs/issue7223.go": true,
"fixedbugs/issue7310.go": true,
"fixedbugs/issue7525.go": true,
"fixedbugs/issue7525b.go": true,
"fixedbugs/issue7525c.go": true,
"fixedbugs/issue7525d.go": true,
"fixedbugs/issue7525e.go": true,
"fixedbugs/issue6889.go": true, // types2 can handle this without constant overflow
"fixedbugs/issue7525.go": true, // init cycle error on different line - ok otherwise
"fixedbugs/issue7525b.go": true, // init cycle error on different line - ok otherwise
"fixedbugs/issue7525c.go": true, // init cycle error on different line - ok otherwise
"fixedbugs/issue7525d.go": true, // init cycle error on different line - ok otherwise
"fixedbugs/issue7525e.go": true, // init cycle error on different line - ok otherwise
"fixedbugs/issue7742.go": true, // type-checking doesn't terminate
"fixedbugs/issue7746.go": true, // type-checking doesn't terminate
}