From 88e292849005889fa89d5e9889049753a377f1e2 Mon Sep 17 00:00:00 2001 From: Richard Musiol Date: Wed, 20 Nov 2013 13:42:30 -0800 Subject: [PATCH] go.tools/go/types: Do not throw error on division of complex variables by zero. See http://play.golang.org/p/DrgLKnHaUW Seems like division of a variable by zero should only throw an error if the variable is an integer. R=golang-dev, mtj, gri CC=golang-dev, gri https://golang.org/cl/29500047 --- go/types/expr.go | 2 +- go/types/testdata/stmt0.src | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/go/types/expr.go b/go/types/expr.go index 4a7890240d..20f64b1537 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) && (x.mode == constant || !isFloat(x.typ)) && y.mode == constant && exact.Sign(y.val) == 0 { + if (op == token.QUO || op == token.REM) && (x.mode == constant || isInteger(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 0921d9f855..9ba0b8e16a 100644 --- a/go/types/testdata/stmt0.src +++ b/go/types/testdata/stmt0.src @@ -57,7 +57,7 @@ func assignments1() { f -= "foo" /* ERROR "cannot convert.*float64" */ c *= 1 - c /= 0 /* ERROR "division by zero" */ + c /= 0 s += "bar" s += 1 /* ERROR "cannot convert.*string" */