]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/compile/internal/types2: better position for "3-index slice of string" error
authorRobert Griesemer <gri@golang.org>
Sat, 13 Nov 2021 21:37:15 +0000 (13:37 -0800)
committerRobert Griesemer <gri@golang.org>
Mon, 15 Nov 2021 21:22:14 +0000 (21:22 +0000)
As a result, slightly narrow position tolerance for tests.

Change-Id: I543dc2b7b9a7940b0684067d1961165b2b4812bb
Reviewed-on: https://go-review.googlesource.com/c/go/+/363670
Trust: Robert Griesemer <gri@golang.org>
Run-TryBot: Robert Griesemer <gri@golang.org>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
src/cmd/compile/internal/types2/check_test.go
src/cmd/compile/internal/types2/index.go
src/cmd/compile/internal/types2/testdata/check/expr3.src
src/cmd/compile/internal/types2/testdata/check/typeparams.go2

index d4c7b7b39b8df5edc0bc47dcbba6f6b976f9a397..ddaacd2443633a9dba059ab5b2d20a0cf2b020fc 100644 (file)
@@ -277,7 +277,7 @@ func TestManual(t *testing.T) {
 
 // TODO(gri) go/types has extra TestLongConstants and TestIndexRepresentability tests
 
-func TestCheck(t *testing.T)     { DefPredeclaredTestFuncs(); testDirFiles(t, "testdata/check", 75, false) } // TODO(gri) narrow column tolerance
+func TestCheck(t *testing.T)     { DefPredeclaredTestFuncs(); testDirFiles(t, "testdata/check", 55, false) } // TODO(gri) narrow column tolerance
 func TestSpec(t *testing.T)      { DefPredeclaredTestFuncs(); testDirFiles(t, "testdata/spec", 0, false) }
 func TestExamples(t *testing.T)  { testDirFiles(t, "testdata/examples", 0, false) }
 func TestFixedbugs(t *testing.T) { testDirFiles(t, "testdata/fixedbugs", 0, false) }
index 524d1957b575b62357097759e8177fd38dea77fa..c773ae8ad3eb3f1f461e00642f924db1af15cfb0 100644 (file)
@@ -222,7 +222,11 @@ func (check *Checker) sliceExpr(x *operand, e *syntax.SliceExpr) {
        case *Basic:
                if isString(u) {
                        if e.Full {
-                               check.error(x, invalidOp+"3-index slice of string")
+                               at := e.Index[2]
+                               if at == nil {
+                                       at = e // e.Index[2] should be present but be careful
+                               }
+                               check.error(at, invalidOp+"3-index slice of string")
                                x.mode = invalid
                                return
                        }
index d1e1dba9f4178c89b10ba9d93fffd791360e985c..523214461f20ccdb6e2c7fa6ed57be8e885c2558 100644 (file)
@@ -110,8 +110,8 @@ func indexes() {
        _ = t[- /* ERROR "negative" */ 1]
        _ = t[- /* ERROR "negative" */ 1 :]
        _ = t[: - /* ERROR "negative" */ 1]
-       _ = t /* ERROR "3-index slice of string" */ [1:2:3]
-       _ = "foo" /* ERROR "3-index slice of string" */ [1:2:3]
+       _ = t[1:2:3 /* ERROR "3-index slice of string" */ ]
+       _ = "foo"[1:2:3 /* ERROR "3-index slice of string" */ ]
        var t0 byte
        t0 = t[0]
        _ = t0
index f77d09391b6a7a6b43cc67b6e8c85f8a31216efe..d72cf078a76f799af2ac9ad8222407a34ad97b78 100644 (file)
@@ -129,7 +129,7 @@ func _[T interface{ ~[10]E }, E any] (x T, i, j, k int) { var _ []E = x[i:j:k] }
 func _[T interface{ ~[]byte }] (x T, i, j, k int) { var _ T = x[i:j] }
 func _[T interface{ ~[]byte }] (x T, i, j, k int) { var _ T = x[i:j:k] }
 func _[T interface{ ~string }] (x T, i, j, k int) { var _ T = x[i:j] }
-func _[T interface{ ~string }] (x T, i, j, k int) { var _ T = x /* ERROR 3-index slice of string */ [i:j:k] }
+func _[T interface{ ~string }] (x T, i, j, k int) { var _ T = x[i:j:k /* ERROR 3-index slice of string */ ] }
 
 type myByte1 []byte
 type myByte2 []byte
@@ -137,7 +137,7 @@ func _[T interface{ []byte | myByte1 | myByte2 }] (x T, i, j, k int) { var _ T =
 func _[T interface{ []byte | myByte1 | []int }] (x T, i, j, k int) { var _ T = x[ /* ERROR no structural type */ i:j:k] }
 
 func _[T interface{ []byte | myByte1 | myByte2 | string }] (x T, i, j, k int) { var _ T = x[i:j] }
-func _[T interface{ []byte | myByte1 | myByte2 | string }] (x T, i, j, k int) { var _ T = x /* ERROR 3-index slice of string */ [i:j:k] }
+func _[T interface{ []byte | myByte1 | myByte2 | string }] (x T, i, j, k int) { var _ T = x[i:j:k /* ERROR 3-index slice of string */ ] }
 func _[T interface{ []byte | myByte1 | []int | string }] (x T, i, j, k int) { var _ T = x[ /* ERROR no structural type */ i:j] }
 
 // len/cap built-ins