mirror of
https://github.com/golang/go
synced 2024-11-26 07:27: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:
parent
c32566c336
commit
810957b155
@ -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))
|
v, valid := constant.Int64Val(constant.ToInt(x.val))
|
||||||
if !valid || max >= 0 && v >= max {
|
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
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -18,5 +18,5 @@ func printmany(nums ...int) {
|
|||||||
func main() {
|
func main() {
|
||||||
printmany(1, 2, 3)
|
printmany(1, 2, 3)
|
||||||
printmany([]int{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\))?"
|
||||||
}
|
}
|
||||||
|
@ -7,14 +7,14 @@
|
|||||||
package p
|
package p
|
||||||
|
|
||||||
func f1() {
|
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)
|
println(a)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func f2() {
|
func f2() {
|
||||||
var a int
|
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)
|
||||||
}
|
}
|
||||||
println(a)
|
println(a)
|
||||||
|
@ -15,7 +15,7 @@ func g() bool { return true }
|
|||||||
func h(int, int) {}
|
func h(int, int) {}
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
f(g()) // ERROR "in argument to f"
|
f(g()) // ERROR "in argument to f|incompatible type"
|
||||||
f(true) // ERROR "in argument to f"
|
f(true) // ERROR "in argument to f|cannot convert"
|
||||||
h(true, true) // ERROR "in argument to h"
|
h(true, true) // ERROR "in argument to h|cannot convert"
|
||||||
}
|
}
|
||||||
|
@ -9,7 +9,7 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
func 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{0: 0} // ERROR "index 0 out of bounds \[0:0\]"
|
||||||
_ = [0]int{5: 25} // ERROR "index 5 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\]"
|
_ = [10]int{2: 10, 15: 30} // ERROR "index 15 out of bounds \[0:10\]"
|
||||||
|
@ -8,4 +8,4 @@
|
|||||||
|
|
||||||
package p
|
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"
|
||||||
|
@ -12,9 +12,9 @@ const bits2 uint = 10
|
|||||||
func main() {
|
func main() {
|
||||||
_ = make([]byte, 1<<bits1)
|
_ = make([]byte, 1<<bits1)
|
||||||
_ = make([]byte, 1<<bits2)
|
_ = make([]byte, 1<<bits2)
|
||||||
_ = make([]byte, nil) // ERROR "non-integer.*len"
|
_ = make([]byte, nil) // ERROR "non-integer.*len|untyped nil"
|
||||||
_ = make([]byte, nil, 2) // ERROR "non-integer.*len"
|
_ = make([]byte, nil, 2) // ERROR "non-integer.*len|untyped nil"
|
||||||
_ = make([]byte, 1, nil) // ERROR "non-integer.*cap"
|
_ = make([]byte, 1, nil) // ERROR "non-integer.*cap|untyped nil"
|
||||||
_ = make([]byte, true) // ERROR "non-integer.*len"
|
_ = make([]byte, true) // ERROR "non-integer.*len|untyped bool"
|
||||||
_ = make([]byte, "abc") // ERROR "non-integer.*len"
|
_ = make([]byte, "abc") // ERROR "non-integer.*len|untyped string"
|
||||||
}
|
}
|
||||||
|
@ -9,7 +9,7 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
_ = copy(nil, []int{}) // ERROR "use of untyped nil"
|
_ = copy(nil, []int{}) // ERROR "use of untyped nil|untyped nil"
|
||||||
_ = copy([]int{}, nil) // ERROR "use of untyped nil"
|
_ = copy([]int{}, nil) // ERROR "use of untyped nil|untyped nil"
|
||||||
_ = 1 + true // ERROR "mismatched types untyped int and untyped bool"
|
_ = 1 + true // ERROR "mismatched types untyped int and untyped bool|untyped int .* untyped bool"
|
||||||
}
|
}
|
||||||
|
19
test/run.go
19
test/run.go
@ -2115,19 +2115,12 @@ var excluded = map[string]bool{
|
|||||||
"fixedbugs/issue6703x.go": true,
|
"fixedbugs/issue6703x.go": true,
|
||||||
"fixedbugs/issue6703y.go": true,
|
"fixedbugs/issue6703y.go": true,
|
||||||
"fixedbugs/issue6703z.go": true,
|
"fixedbugs/issue6703z.go": true,
|
||||||
"fixedbugs/issue6750.go": true,
|
"fixedbugs/issue6889.go": true, // types2 can handle this without constant overflow
|
||||||
"fixedbugs/issue6772.go": true,
|
"fixedbugs/issue7525.go": true, // init cycle error on different line - ok otherwise
|
||||||
"fixedbugs/issue6889.go": true,
|
"fixedbugs/issue7525b.go": true, // init cycle error on different line - ok otherwise
|
||||||
"fixedbugs/issue7129.go": true,
|
"fixedbugs/issue7525c.go": true, // init cycle error on different line - ok otherwise
|
||||||
"fixedbugs/issue7150.go": true,
|
"fixedbugs/issue7525d.go": true, // init cycle error on different line - ok otherwise
|
||||||
"fixedbugs/issue7153.go": true,
|
"fixedbugs/issue7525e.go": true, // init cycle error on different line - ok otherwise
|
||||||
"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/issue7742.go": true, // type-checking doesn't terminate
|
"fixedbugs/issue7742.go": true, // type-checking doesn't terminate
|
||||||
"fixedbugs/issue7746.go": true, // type-checking doesn't terminate
|
"fixedbugs/issue7746.go": true, // type-checking doesn't terminate
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user