]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/compile/internal/types2: add missing tests from go/types
authorRobert Griesemer <gri@golang.org>
Tue, 6 Jun 2023 23:25:26 +0000 (16:25 -0700)
committerGopher Robot <gobot@golang.org>
Mon, 12 Jun 2023 16:28:21 +0000 (16:28 +0000)
Add 3 tests that exist in go/types but that were not ported to types2.

Change-Id: I34d219f605f9ae66e8b4439c3dfe93cfa0ec9524
Reviewed-on: https://go-review.googlesource.com/c/go/+/501304
Reviewed-by: Robert Findley <rfindley@google.com>
Reviewed-by: Robert Griesemer <gri@google.com>
Auto-Submit: Robert Griesemer <gri@google.com>
Run-TryBot: Robert Griesemer <gri@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>

src/cmd/compile/internal/types2/check_test.go

index b149ae3908907b1be015b79a92426b122f0cdb51..8cb3000501c1d8b094f4d95b3ff6c99317b015b0 100644 (file)
@@ -317,7 +317,32 @@ func TestManual(t *testing.T) {
        }
 }
 
-// TODO(gri) go/types has extra TestLongConstants and TestIndexRepresentability tests
+func TestLongConstants(t *testing.T) {
+       format := `package longconst; const _ = %s /* ERROR "constant overflow" */; const _ = %s // ERROR "excessively long constant"`
+       src := fmt.Sprintf(format, strings.Repeat("1", 9999), strings.Repeat("1", 10001))
+       testFiles(t, []string{"longconst.go"}, [][]byte{[]byte(src)}, 0, false)
+}
+
+func withSizes(sizes Sizes) func(*Config) {
+       return func(cfg *Config) {
+               cfg.Sizes = sizes
+       }
+}
+
+// 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; var s []byte; var _ = s[int64 /* ERRORx "int64\\(1\\) << 40 \\(.*\\) overflows int" */ (1) << 40]`
+       testFiles(t, []string{"index.go"}, [][]byte{[]byte(src)}, 0, false, withSizes(&StdSizes{4, 4}))
+}
+
+func TestIssue47243_TypedRHS(t *testing.T) {
+       // The RHS of the shift expression below overflows uint on 32bit platforms,
+       // but this is OK as it is explicitly typed.
+       const src = `package issue47243; var a uint64; var _ = a << uint64(4294967296)` // uint64(1<<32)
+       testFiles(t, []string{"p.go"}, [][]byte{[]byte(src)}, 0, false, withSizes(&StdSizes{4, 4}))
+}
 
 func TestCheck(t *testing.T) {
        DefPredeclaredTestFuncs()