Commit 8ad027c0 authored by Matthew Dempsky's avatar Matthew Dempsky

go/types: nicer shift error message

Updates #13940.

Change-Id: I41974c292dd981d82ac03b9b8b406713445362c3
Reviewed-on: https://go-review.googlesource.com/20081
Run-TryBot: Matthew Dempsky <mdempsky@google.com>
Reviewed-by: 's avatarBrad Fitzpatrick <bradfitz@golang.org>
parent 86235d5d
......@@ -660,10 +660,10 @@ func (check *Checker) shift(x, y *operand, e *ast.BinaryExpr, op token.Token) {
return
}
// rhs must be within reasonable bounds
const stupidShift = 1023 - 1 + 52 // so we can express smallestFloat64
const shiftBound = 1023 - 1 + 52 // so we can express smallestFloat64
s, ok := constant.Uint64Val(yval)
if !ok || s > stupidShift {
check.invalidOp(y.pos(), "stupid shift count %s", y)
if !ok || s > shiftBound {
check.invalidOp(y.pos(), "invalid shift count %s", y)
x.mode = invalid
return
}
......
......@@ -10,8 +10,8 @@ func shifts0() {
s = 10
_ = 0<<0
_ = 1<<s
_ = 1<<- /* ERROR "stupid shift" */ 1
_ = 1<<1075 /* ERROR "stupid shift" */
_ = 1<<- /* ERROR "invalid shift" */ 1
_ = 1<<1075 /* ERROR "invalid shift" */
_ = 2.0<<1
_ int = 2<<s
......@@ -338,4 +338,4 @@ func issue11594() {
_ = float64 /* ERROR "must be integer" */ (0) >> 2
_ = complex64 /* ERROR "must be integer" */ (0) << 3
_ = complex64 /* ERROR "must be integer" */ (0) >> 4
}
\ No newline at end of file
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment