Skip to content

Commit 08e00c0

Browse files
authored
Fix /(::Zero, ::AbstractMutable) (#355)
1 parent 38327fa commit 08e00c0

3 files changed

Lines changed: 14 additions & 2 deletions

File tree

src/dispatch.jl

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,13 @@ Base.:+(x::AbstractMutable, ::Zero) = copy_if_mutable(x)
2323
Base.:-(::Zero, x::AbstractMutable) = operate(-, x)
2424
Base.:-(x::AbstractMutable, ::Zero) = copy_if_mutable(x)
2525

26+
function Base.:/(z::Zero, x::AbstractMutable)
27+
if iszero(x)
28+
throw(DivideError())
29+
end
30+
return z
31+
end
32+
2633
function Base.sum(
2734
a::AbstractArray{T};
2835
dims = :,

src/rewrite.jl

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,9 +85,8 @@ Base.:*(z::Zero) = z
8585
function Base.:/(z::Zero, x::Number)
8686
if iszero(x)
8787
throw(DivideError())
88-
else
89-
return z
9088
end
89+
return z
9190
end
9291

9392
Base.iszero(::Zero) = true

test/test_basics.jl

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -546,6 +546,12 @@ function test_operate()
546546
return
547547
end
548548

549+
function test_op_divide()
550+
@test MA.Zero() / DummyBigInt(1) == MA.Zero()
551+
@test_throws DivideError MA.Zero() / DummyBigInt(0)
552+
return
553+
end
554+
549555
end # TestBasics
550556

551557
TestBasics.runtests()

0 commit comments

Comments
 (0)