]> Cypherpunks repositories - gostls13.git/commitdiff
[dev.typeparams] cmd/compile/internal/types2: adjusted array error message for compiler
authorRobert Griesemer <gri@golang.org>
Wed, 9 Dec 2020 01:48:39 +0000 (17:48 -0800)
committerRobert Griesemer <gri@golang.org>
Wed, 9 Dec 2020 23:54:59 +0000 (23:54 +0000)
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>
src/cmd/compile/internal/types2/expr.go
test/fixedbugs/issue6750.go
test/fixedbugs/issue6772.go
test/fixedbugs/issue7129.go
test/fixedbugs/issue7150.go
test/fixedbugs/issue7153.go
test/fixedbugs/issue7223.go
test/fixedbugs/issue7310.go
test/run.go

index c68077547e77b484d1dc9993821ffba38f67753c..bede0c639d430ccea9b9af4efb010f3748a93b06 100644 (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
        }
 
index f62a85009c0fbb396bc6d818cb06094ced453543..fca4e66aafe7615c0d52e4a42f861c4289e80ed1 100644 (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\))?"
 }
index 4d0001c870d7a5fd62749d2cf9a70a1e5d56345d..cb8d0a11f2181203557051fe7c80750623a09cf8 100644 (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)
index 2425cbd3439ede2e15a56450c12cf28198703e64..14fc418150f75b0bdad03a4235007a447e93eb6d 100644 (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"
 }
index 8a8a7d088fc8f540b60d12eac2a2b2584dd2e6b0..4bd9de8645fd86728f2f2d1a105c74d863d550e9 100644 (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\]"
index 66b1338496f298658cf969ea5f2dcc4135b12604..7a85fb8779cdc067fd204f5400b5ed561bc0e929 100644 (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"
index 0ec3476403dbe45bac7856ffc1d11aa7c0499041..c78de287ff61f3988c54a9a1c8eeb0a103d7f0fc 100644 (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"
 }
index 6829d5e126bf343a956ff9d3ca6c2611c0d5ef8a..ef099ce41ec9de48309a1858b1533cd56f3995c7 100644 (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"
 }
index 32c74e8210f9d5696456861c21a68f2cd3c16915..891b9572b743e39d0eacf5f4b72e5b79adcabaa7 100644 (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
 }