mirror of
https://github.com/golang/go
synced 2024-11-19 01:54:39 -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:
parent
2e33158b60
commit
88e2928490
@ -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
|
||||
|
2
go/types/testdata/stmt0.src
vendored
2
go/types/testdata/stmt0.src
vendored
@ -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" */
|
||||
|
Loading…
Reference in New Issue
Block a user