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:
parent
cadc2255fe
commit
cfc002f30b
|
@ -762,7 +762,7 @@ func (check *checker) binary(x *operand, lhs, rhs ast.Expr, op token.Token) {
|
||||||
return
|
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")
|
check.invalidOp(y.pos(), "division by zero")
|
||||||
x.mode = invalid
|
x.mode = invalid
|
||||||
return
|
return
|
||||||
|
|
|
@ -52,6 +52,8 @@ func assignments1() {
|
||||||
i += "foo" /* ERROR "cannot convert.*int" */
|
i += "foo" /* ERROR "cannot convert.*int" */
|
||||||
|
|
||||||
f -= 1
|
f -= 1
|
||||||
|
f /= 0
|
||||||
|
f = float32(1.0)/0
|
||||||
f -= "foo" /* ERROR "cannot convert.*float64" */
|
f -= "foo" /* ERROR "cannot convert.*float64" */
|
||||||
|
|
||||||
c *= 1
|
c *= 1
|
||||||
|
|
Loading…
Reference in New Issue