Skip to content

Commit

Permalink
[dev.typeparams] cmd/compile/internal/types2: adjusted array error me…
Browse files Browse the repository at this point in the history
…ssage 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>
  • Loading branch information
griesemer committed Dec 9, 2020
1 parent c32566c commit 810957b
Show file tree
Hide file tree
Showing 9 changed files with 27 additions and 30 deletions.
6 changes: 5 additions & 1 deletion src/cmd/compile/internal/types2/expr.go
Expand Up @@ -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
}

Expand Down
2 changes: 1 addition & 1 deletion test/fixedbugs/issue6750.go
Expand Up @@ -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\))?"
}
4 changes: 2 additions & 2 deletions test/fixedbugs/issue6772.go
Expand Up @@ -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)
Expand Down
6 changes: 3 additions & 3 deletions test/fixedbugs/issue7129.go
Expand Up @@ -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"
}
2 changes: 1 addition & 1 deletion test/fixedbugs/issue7150.go
Expand Up @@ -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\]"
Expand Down
2 changes: 1 addition & 1 deletion test/fixedbugs/issue7153.go
Expand Up @@ -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"
10 changes: 5 additions & 5 deletions test/fixedbugs/issue7223.go
Expand Up @@ -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"
}
6 changes: 3 additions & 3 deletions test/fixedbugs/issue7310.go
Expand Up @@ -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"
}
19 changes: 6 additions & 13 deletions test/run.go
Expand Up @@ -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
}

0 comments on commit 810957b

Please sign in to comment.