From cfc002f30b7028be0edba24d5d084b62066fbf9b Mon Sep 17 00:00:00 2001 From: Richard Musiol Date: Wed, 13 Nov 2013 15:16:19 -0800 Subject: [PATCH] go.tools/go/types: Do not throw error on division of float variables by zero. R=golang-dev, gri CC=golang-dev https://golang.org/cl/26040043 --- go/types/expr.go | 2 +- go/types/testdata/stmt0.src | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/go/types/expr.go b/go/types/expr.go index 0702d360..4a789024 100644 --- a/go/types/expr.go +++ b/go/types/expr.go @@ -762,7 +762,7 @@ func (check *checker) binary(x *operand, lhs, rhs ast.Expr, op token.Token) { return } - if (op == token.QUO || op == token.REM) && y.mode == constant && exact.Sign(y.val) == 0 { + if (op == token.QUO || op == token.REM) && (x.mode == constant || !isFloat(x.typ)) && y.mode == constant && exact.Sign(y.val) == 0 { check.invalidOp(y.pos(), "division by zero") x.mode = invalid return diff --git a/go/types/testdata/stmt0.src b/go/types/testdata/stmt0.src index f7be5d90..167c9ce6 100644 --- a/go/types/testdata/stmt0.src +++ b/go/types/testdata/stmt0.src @@ -52,6 +52,8 @@ func assignments1() { i += "foo" /* ERROR "cannot convert.*int" */ f -= 1 + f /= 0 + f = float32(1.0)/0 f -= "foo" /* ERROR "cannot convert.*float64" */ c *= 1