From af1b3e77ccd02d62572289c9286b6cec404d1ae1 Mon Sep 17 00:00:00 2001 From: odow Date: Wed, 24 Apr 2024 16:35:49 +1200 Subject: [PATCH] Implement Base.zero(::Type{MA.Zero}) --- src/rewrite.jl | 4 ++++ test/rewrite.jl | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/src/rewrite.jl b/src/rewrite.jl index 9c054a61..44d43a75 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 73216a88..e2d1c8ae 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