1
0
mirror of https://github.com/golang/go synced 2024-11-19 02:44:44 -07:00

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
This commit is contained in:
Richard Musiol 2013-11-13 15:16:19 -08:00 committed by Robert Griesemer
parent cadc2255fe
commit cfc002f30b
2 changed files with 3 additions and 1 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) && 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

View File

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