go/types: add missing test for constant shifts · golang/go@e9a746d (original) (raw)

Original file line number Diff line number Diff line change
@@ -620,7 +620,7 @@ func (check *Checker) shift(x, y *operand, op token.Token) {
620 620
621 621 // The lhs must be of integer type or be representable
622 622 // as an integer; otherwise the shift has no chance.
623 -if !isInteger(x.typ) && (!untypedx |
623 +if !x.isInteger() {
624 624 check.invalidOp(x.pos(), "shifted operand %s must be integer", x)
625 625 x.mode = invalid
626 626 return
@@ -646,6 +646,12 @@ func (check *Checker) shift(x, y *operand, op token.Token) {
646 646
647 647 if x.mode == constant {
648 648 if y.mode == constant {
649 +// rhs must be an integer value
650 +if !y.isInteger() {
651 +check.invalidOp(y.pos(), "shift count %s must be unsigned integer", y)
652 +x.mode = invalid
653 +return
654 + }
649 655 // rhs must be within reasonable bounds
650 656 const stupidShift = 1023 - 1 + 52 // so we can express smallestFloat64
651 657 s, ok := exact.Uint64Val(y.val)