1
0
mirror of https://github.com/golang/go synced 2024-11-19 01:04:40 -07:00

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
This commit is contained in:
Richard Musiol 2013-11-20 13:42:30 -08:00 committed by Robert Griesemer
parent 2e33158b60
commit 88e2928490
2 changed files with 2 additions and 2 deletions

View File

@ -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

View File

@ -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" */