diff --git a/go/types/expr.go b/go/types/expr.go index 0702d36039b..4a7890240d7 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 f7be5d90cdc..167c9ce62dd 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