mirror of
https://github.com/golang/go
synced 2024-11-12 05:50:21 -07:00
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: Brad Fitzpatrick <bradfitz@golang.org>
This commit is contained in:
parent
86235d5dd7
commit
8ad027c0c4
@ -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
|
||||
}
|
||||
|
6
src/go/types/testdata/shifts.src
vendored
6
src/go/types/testdata/shifts.src
vendored
@ -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
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user