Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions src/dispatch.jl
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,13 @@ Base.:+(x::AbstractMutable, ::Zero) = copy_if_mutable(x)
Base.:-(::Zero, x::AbstractMutable) = operate(-, x)
Base.:-(x::AbstractMutable, ::Zero) = copy_if_mutable(x)

function Base.:/(z::Zero, x::AbstractMutable)
if iszero(x)
throw(DivideError())
end
return z
end

function Base.sum(
a::AbstractArray{T};
dims = :,
Expand Down
3 changes: 1 addition & 2 deletions src/rewrite.jl
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,8 @@ Base.:*(z::Zero) = z
function Base.:/(z::Zero, x::Number)
if iszero(x)
throw(DivideError())
else
return z
end
return z
end

Base.iszero(::Zero) = true
Expand Down
6 changes: 6 additions & 0 deletions test/test_basics.jl
Original file line number Diff line number Diff line change
Expand Up @@ -546,6 +546,12 @@ function test_operate()
return
end

function test_op_divide()
@test MA.Zero() / DummyBigInt(1) == MA.Zero()
@test_throws DivideError MA.Zero() / DummyBigInt(0)
return
end

end # TestBasics

TestBasics.runtests()
Loading