diff --git a/src/rewrite.jl b/src/rewrite.jl index 9c054a6..44d43a7 100644 --- a/src/rewrite.jl +++ b/src/rewrite.jl @@ -30,6 +30,10 @@ end struct Zero end +# This method is called in various `promote_operation_fallback` methods if one +# of the arguments is `::Zero`. +Base.zero(::Type{Zero}) = Zero() + ## We need to copy `x` as it will be used as might be given by the user and be ## given as first argument of `operate!!`. #Base.:(+)(zero::Zero, x) = copy_if_mutable(x) diff --git a/test/rewrite.jl b/test/rewrite.jl index 73216a8..e2d1c8a 100644 --- a/test/rewrite.jl +++ b/test/rewrite.jl @@ -9,7 +9,7 @@ import MutableArithmetics as MA @testset "Zero" begin z = MA.Zero() - #@test zero(MA.Zero) isa MA.Zero + @test zero(MA.Zero) isa MA.Zero @test z + z isa MA.Zero @test z + 1 == 1 @test 1 + z == 1