]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/compile/internal/types2: pass pos argument to Checker.overflow
authorRobert Griesemer <gri@golang.org>
Mon, 8 May 2023 21:46:17 +0000 (14:46 -0700)
committerGopher Robot <gobot@golang.org>
Mon, 8 May 2023 22:07:01 +0000 (22:07 +0000)
This matches the go/types version of Checker.overflow.
Preparation for generating this function (and others)
for go/types.

Change-Id: I84117203247011bd2e96c9cf53fd5a443e528bbf
Reviewed-on: https://go-review.googlesource.com/c/go/+/493558
TryBot-Result: Gopher Robot <gobot@golang.org>
Auto-Submit: Robert Griesemer <gri@google.com>
Reviewed-by: Robert Griesemer <gri@google.com>
Reviewed-by: Robert Findley <rfindley@google.com>
Run-TryBot: Robert Griesemer <gri@google.com>

src/cmd/compile/internal/types2/expr.go

index 93ca24addc19efd13ff219e0d1f409fa0c2b01f9..4dc46d4a486f8b94febc30f12acb00d51c4f8097 100644 (file)
@@ -87,14 +87,14 @@ func (check *Checker) op(m opPredicates, x *operand, op syntax.Operator) bool {
 // overflow checks that the constant x is representable by its type.
 // For untyped constants, it checks that the value doesn't become
 // arbitrarily large.
-func (check *Checker) overflow(x *operand) {
+func (check *Checker) overflow(x *operand, pos syntax.Pos) {
        assert(x.mode == constant_)
 
        if x.val.Kind() == constant.Unknown {
                // TODO(gri) We should report exactly what went wrong. At the
                //           moment we don't have the (go/constant) API for that.
                //           See also TODO in go/constant/value.go.
-               check.error(opPos(x.expr), InvalidConstVal, "constant result is not representable")
+               check.error(pos, InvalidConstVal, "constant result is not representable")
                return
        }
 
@@ -114,7 +114,7 @@ func (check *Checker) overflow(x *operand) {
                if op != "" {
                        op += " "
                }
-               check.errorf(opPos(x.expr), InvalidConstVal, "constant %soverflow", op)
+               check.errorf(pos, InvalidConstVal, "constant %soverflow", op)
                x.val = constant.MakeUnknown()
        }
 }
@@ -242,7 +242,7 @@ func (check *Checker) unary(x *operand, e *syntax.Operation) {
                }
                x.val = constant.UnaryOp(op2tok[op], x.val, prec)
                x.expr = e
-               check.overflow(x)
+               check.overflow(x, opPos(x.expr))
                return
        }
 
@@ -1020,7 +1020,7 @@ func (check *Checker) shift(x, y *operand, e syntax.Expr, op syntax.Operator) {
                        // x is a constant so xval != nil and it must be of Int kind.
                        x.val = constant.Shift(xval, op2tok[op], uint(s))
                        x.expr = e
-                       check.overflow(x)
+                       check.overflow(x, opPos(x.expr))
                        return
                }
 
@@ -1221,7 +1221,7 @@ func (check *Checker) binary(x *operand, e syntax.Expr, lhs, rhs syntax.Expr, op
                }
                x.val = constant.BinaryOp(x.val, tok, y.val)
                x.expr = e
-               check.overflow(x)
+               check.overflow(x, opPos(x.expr))
                return
        }
 
@@ -1360,7 +1360,7 @@ func (check *Checker) exprInternal(T Type, x *operand, e syntax.Expr, hint Type)
                }
                // Ensure that integer values don't overflow (go.dev/issue/54280).
                x.expr = e // make sure that check.overflow below has an error position
-               check.overflow(x)
+               check.overflow(x, opPos(x.expr))
 
        case *syntax.FuncLit:
                if sig, ok := check.typ(e.Type).(*Signature); ok {