1
0
mirror of https://github.com/golang/go synced 2024-11-11 18:51:37 -07:00

cmd/compile/internal/types2: add missing tests from go/types

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>
This commit is contained in:
Robert Griesemer 2023-06-06 16:25:26 -07:00 committed by Gopher Robot
parent f35d2dae74
commit eaa4b1a6e4

View 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()