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:
parent
cadc2255fe
commit
cfc002f30b
@ -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
|
||||
|
2
go/types/testdata/stmt0.src
vendored
2
go/types/testdata/stmt0.src
vendored
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user