From 33ff1559702388c57c45f9e6cd032f06e8c3c163 Mon Sep 17 00:00:00 2001 From: Rob Findley Date: Mon, 26 Jul 2021 16:33:44 -0400 Subject: go/types: preserve untyped constants on the RHS of a shift expression CL 291316 fixed go/types to verify that untyped shift counts are representable by uint, but as a side effect also converted their types to uint. Rearrange the logic to keep the check for representability, but not actually convert untyped integer constants. Untyped non-integer constants are still converted, to preserve the behavior of 1.16. This behavior for non-integer types is a bug, filed as #47410. Updates #47410 Fixes #47243 Change-Id: I5eab4aab35b97f932fccdee2d4a18623ee2ccad5 Reviewed-on: https://go-review.googlesource.com/c/go/+/337529 Trust: Robert Findley Trust: Robert Griesemer Run-TryBot: Robert Findley TryBot-Result: Go Bot Reviewed-by: Robert Griesemer --- src/go/types/check_test.go | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'src/go/types/check_test.go') diff --git a/src/go/types/check_test.go b/src/go/types/check_test.go index c85a8e46fb..f83abf11ce 100644 --- a/src/go/types/check_test.go +++ b/src/go/types/check_test.go @@ -344,6 +344,13 @@ func TestIssue46453(t *testing.T) { checkFiles(t, nil, "", []string{"issue46453.go"}, [][]byte{[]byte(src)}, false, nil) } +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\n\nvar a uint64; var _ = a << uint64(4294967296)" // uint64(1<<32) + checkFiles(t, &StdSizes{4, 4}, "", []string{"p.go"}, [][]byte{[]byte(src)}, false, nil) +} + func TestCheck(t *testing.T) { DefPredeclaredTestFuncs(); testDir(t, "check") } func TestExamples(t *testing.T) { testDir(t, "examples") } func TestFixedbugs(t *testing.T) { testDir(t, "fixedbugs") } -- cgit v1.2.3-54-g00ecf