]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/compile: use "shifted operand %s (type %s) must be integer" for some shift errors
authorRobert Griesemer <gri@golang.org>
Wed, 28 Sep 2022 21:42:16 +0000 (14:42 -0700)
committerGopher Robot <gobot@golang.org>
Wed, 28 Sep 2022 22:28:41 +0000 (22:28 +0000)
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>

src/cmd/compile/internal/types2/expr.go
src/go/types/expr.go
test/fixedbugs/issue28079c.go

index 06fb9bb9f92a0f07fd79125d6387248d8cdc3466..5b40b94681e060d0818021e1e31cba7c6cd5da93 100644 (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
                // 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
index 710205abbac3c2310380e8a42fc1f427edd2d4e7..7f958927187c9d55f14b2800b2701040397d55f3 100644 (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
                // 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
index dfac8d01554737f8ebdc93f51b522a562479a272..59ba0d1a526adbb1fca011b0fee0200ea6bc6ae6 100644 (file)
@@ -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"
 }