mirror of
https://github.com/golang/go.git
synced 2025-05-05 15:43:04 +00:00
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:
parent
7997e5f254
commit
8c29881dd1
@ -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
|
||||
// as an integer if it is a constant.
|
||||
if !allInteger(typ) {
|
||||
if check.conf.CompilerErrorMessages {
|
||||
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)
|
||||
}
|
||||
check.errorf(x, _InvalidShiftOperand, invalidOp+"shifted operand %s (type %s) must be integer", x, typ)
|
||||
return
|
||||
}
|
||||
// Even if we have an integer, if the value is a constant we
|
||||
|
@ -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
|
||||
// as an integer if it is a constant.
|
||||
if !allInteger(typ) {
|
||||
if compilerErrorMessages {
|
||||
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)
|
||||
}
|
||||
check.invalidOp(x, _InvalidShiftOperand, "shifted operand %s (type %s) must be integer", x, typ)
|
||||
return
|
||||
}
|
||||
// Even if we have an integer, if the value is a constant we
|
||||
|
@ -11,5 +11,5 @@ package p
|
||||
import "unsafe"
|
||||
|
||||
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"
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user