Skip to content

Commit

Permalink
Fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
blegat committed Jul 23, 2024
1 parent faf35f8 commit 9848cfc
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/rewrite.jl
Original file line number Diff line number Diff line change
Expand Up @@ -59,15 +59,19 @@ broadcast!!(::typeof(add_mul), ::Zero, x, y) = x * y

# Needed in `@rewrite(1 .+ sum(1 for i in 1:0) * 1^2)`
Base.:*(z::Zero, ::Any) = z
Base.:*(z::Zero, ::Number) = z
Base.:*(::Any, z::Zero) = z
Base.:*(::Number, z::Zero) = z
Base.:*(z::Zero, ::Zero) = z
Base.:+(::Zero, x::Any) = x
Base.:+(::Zero, x::Number) = x
Base.:+(x::Any, ::Zero) = x
Base.:+(x::Number, ::Zero) = x
Base.:+(z::Zero, ::Zero) = z
Base.:-(::Zero, x::Any) = -x
Base.:-(::Zero, x::Number) = -x
Base.:-(x::Any, ::Zero) = x
Base.:-(x::Number, ::Zero) = x
Base.:-(z::Zero, ::Zero) = z
Base.:-(z::Zero) = z
Base.:+(z::Zero) = z
Expand All @@ -81,6 +85,14 @@ function Base.:/(z::Zero, x::Any)
end
end

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

# These methods are used to provide an efficient implementation for the common
# case like `x^2 * sum(f for i in 1:0)`, which lowers to
# `_MA.operate!!(*, x^2, _MA.Zero())`. We don't need the method with reversed
Expand Down

0 comments on commit 9848cfc

Please sign in to comment.