Fixes #56425.
Change-Id: Ieae3fdb5326d4b6f6ec1cdcd579051559e34b35b
Reviewed-on: https://go-review.googlesource.com/c/go/+/445515
Reviewed-by: Robert Findley <rfindley@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Run-TryBot: Robert Griesemer <gri@google.com>
Reviewed-by: Robert Griesemer <gri@google.com>
Auto-Submit: Robert Griesemer <gri@google.com>
// Check that constants are representable by uint, but do not convert them
// (see also issue #47243).
+ var yval constant.Value
if y.mode == constant_ {
// Provide a good error message for negative shift counts.
- yval := constant.ToInt(y.val) // consider -1, 1.0, but not -1.1
+ yval = constant.ToInt(y.val) // consider -1, 1.0, but not -1.1
if yval.Kind() == constant.Int && constant.Sign(yval) < 0 {
check.errorf(y, InvalidShiftCount, invalidOp+"negative shift count %s", y)
x.mode = invalid
}
// rhs must be within reasonable bounds in constant shifts
const shiftBound = 1023 - 1 + 52 // so we can express smallestFloat64 (see issue #44057)
- s, ok := constant.Uint64Val(y.val)
+ s, ok := constant.Uint64Val(yval)
if !ok || s > shiftBound {
check.errorf(y, InvalidShiftCount, invalidOp+"invalid shift count %s", y)
x.mode = invalid
// Check that constants are representable by uint, but do not convert them
// (see also issue #47243).
+ var yval constant.Value
if y.mode == constant_ {
// Provide a good error message for negative shift counts.
- yval := constant.ToInt(y.val) // consider -1, 1.0, but not -1.1
+ yval = constant.ToInt(y.val) // consider -1, 1.0, but not -1.1
if yval.Kind() == constant.Int && constant.Sign(yval) < 0 {
check.errorf(y, InvalidShiftCount, invalidOp+"negative shift count %s", y)
x.mode = invalid
}
// rhs must be within reasonable bounds in constant shifts
const shiftBound = 1023 - 1 + 52 // so we can express smallestFloat64 (see issue #44057)
- s, ok := constant.Uint64Val(y.val)
+ s, ok := constant.Uint64Val(yval)
if !ok || s > shiftBound {
check.errorf(y, InvalidShiftCount, invalidOp+"invalid shift count %s", y)
x.mode = invalid
--- /dev/null
+// Copyright 2022 The Go Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+package p
+
+const s float32 = 0
+var _ = 0 << s