cmd/compile: use "shifted operand %s (type %s) must be integer" for some shift errors

This matches what go/types and types2 report and it also matches
the compiler errors reported for some related shift problems.

For #55326.

Change-Id: Iee40e8d988d5a7f9ff2c49f019884d02485c9fdf
Reviewed-on: https://go-review.googlesource.com/c/go/+/436177
Auto-Submit: Robert Griesemer <gri@google.com>
Reviewed-by: Robert Griesemer <gri@google.com>
Run-TryBot: Robert Griesemer <gri@google.com>
Reviewed-by: Robert Findley <rfindley@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
This commit is contained in:
Robert Griesemer 2022-09-28 14:42:16 -07:00 committed by Gopher Robot
parent 7997e5f254
commit 8c29881dd1
3 changed files with 3 additions and 11 deletions

View File

@ -616,11 +616,7 @@ func (check *Checker) updateExprType0(parent, x syntax.Expr, typ Type, final boo
// We already know from the shift check that it is representable // We already know from the shift check that it is representable
// as an integer if it is a constant. // as an integer if it is a constant.
if !allInteger(typ) { if !allInteger(typ) {
if check.conf.CompilerErrorMessages { check.errorf(x, _InvalidShiftOperand, invalidOp+"shifted operand %s (type %s) must be integer", x, typ)
check.errorf(x, _InvalidShiftOperand, invalidOp+"%s (shift of type %s)", parent, typ)
} else {
check.errorf(x, _InvalidShiftOperand, invalidOp+"shifted operand %s (type %s) must be integer", x, typ)
}
return return
} }
// Even if we have an integer, if the value is a constant we // Even if we have an integer, if the value is a constant we

View File

@ -579,11 +579,7 @@ func (check *Checker) updateExprType0(parent, x ast.Expr, typ Type, final bool)
// We already know from the shift check that it is representable // We already know from the shift check that it is representable
// as an integer if it is a constant. // as an integer if it is a constant.
if !allInteger(typ) { if !allInteger(typ) {
if compilerErrorMessages { check.invalidOp(x, _InvalidShiftOperand, "shifted operand %s (type %s) must be integer", x, typ)
check.invalidOp(x, _InvalidShiftOperand, "%s (shift of type %s)", parent, typ)
} else {
check.invalidOp(x, _InvalidShiftOperand, "shifted operand %s (type %s) must be integer", x, typ)
}
return return
} }
// Even if we have an integer, if the value is a constant we // Even if we have an integer, if the value is a constant we

View File

@ -11,5 +11,5 @@ package p
import "unsafe" import "unsafe"
func f() { func f() {
_ = complex(1<<uintptr(unsafe.Pointer(nil)), 0) // ERROR "invalid operation: .*shift of type float64.*|non-integer type for left operand of shift" _ = complex(1<<uintptr(unsafe.Pointer(nil)), 0) // ERROR "invalid operation: shifted operand 1 \(type float64\) must be integer|non-integer type for left operand of shift"
} }