aboutsummaryrefslogtreecommitdiff
path: root/src/go/types/check_test.go
diff options
context:
space:
mode:
authorMatthew Dempsky <mdempsky@google.com>2021-04-21 18:22:35 -0700
committerMatthew Dempsky <mdempsky@google.com>2021-04-22 21:23:59 +0000
commitf7afdfd48383c4f0ea8653ea9f8c7b9a3d93abee (patch)
tree0cb2a09d6cf70f1e9d070b24a72add0b16c4d3aa /src/go/types/check_test.go
parentcfe5d79c5c2c9888a0e56e089dca99e405a225b9 (diff)
downloadgo-f7afdfd48383c4f0ea8653ea9f8c7b9a3d93abee.tar.gz
go-f7afdfd48383c4f0ea8653ea9f8c7b9a3d93abee.zip
go/types: cleanup and fix Checker.index
A couple minor spec compliance issues: constant, typed index operands must still be representable as type "int", but should also be recorded as their original type. Fixes #45667. Change-Id: Iefeb29f20a8e48350af83a62c9ae0e92198c5ef7 Reviewed-on: https://go-review.googlesource.com/c/go/+/312591 Trust: Matthew Dempsky <mdempsky@google.com> Trust: Robert Griesemer <gri@golang.org> Run-TryBot: Matthew Dempsky <mdempsky@google.com> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Robert Findley <rfindley@google.com> Reviewed-by: Robert Griesemer <gri@golang.org>
Diffstat (limited to 'src/go/types/check_test.go')
-rw-r--r--src/go/types/check_test.go15
1 files changed, 12 insertions, 3 deletions
diff --git a/src/go/types/check_test.go b/src/go/types/check_test.go
index 8a15841e37..422488744b 100644
--- a/src/go/types/check_test.go
+++ b/src/go/types/check_test.go
@@ -203,7 +203,7 @@ func asGoVersion(s string) string {
return ""
}
-func checkFiles(t *testing.T, goVersion string, filenames []string, srcs [][]byte) {
+func checkFiles(t *testing.T, sizes Sizes, goVersion string, filenames []string, srcs [][]byte) {
if len(filenames) == 0 {
t.Fatal("no source files")
}
@@ -239,6 +239,7 @@ func checkFiles(t *testing.T, goVersion string, filenames []string, srcs [][]byt
// typecheck and collect typechecker errors
var conf Config
+ conf.Sizes = sizes
conf.GoVersion = goVersion
// special case for importC.src
@@ -310,7 +311,15 @@ func TestCheck(t *testing.T) {
func TestLongConstants(t *testing.T) {
format := "package longconst\n\nconst _ = %s\nconst _ = %s // ERROR excessively long constant"
src := fmt.Sprintf(format, strings.Repeat("1", 9999), strings.Repeat("1", 10001))
- checkFiles(t, "", []string{"longconst.go"}, [][]byte{[]byte(src)})
+ checkFiles(t, nil, "", []string{"longconst.go"}, [][]byte{[]byte(src)})
+}
+
+// TestIndexRepresentability tests that constant index operands must
+// be representable as int even if they already have a type that can
+// represent larger values.
+func TestIndexRepresentability(t *testing.T) {
+ const src = "package index\n\nvar s []byte\nvar _ = s[int64 /* ERROR \"int64\\(1\\) << 40 \\(.*\\) overflows int\" */ (1) << 40]"
+ checkFiles(t, &StdSizes{4, 4}, "", []string{"index.go"}, [][]byte{[]byte(src)})
}
func TestTestdata(t *testing.T) { DefPredeclaredTestFuncs(); testDir(t, "testdata") }
@@ -358,5 +367,5 @@ func testPkg(t *testing.T, filenames []string, goVersion string) {
}
srcs[i] = src
}
- checkFiles(t, goVersion, filenames, srcs)
+ checkFiles(t, nil, goVersion, filenames, srcs)
}