Skip to content

Commit

Permalink
Implement Base.zero(::Type{MA.Zero}) (#283)
Browse files Browse the repository at this point in the history
  • Loading branch information
odow authored Apr 24, 2024
1 parent cbf8d63 commit 3c94705
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
4 changes: 4 additions & 0 deletions src/rewrite.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion test/rewrite.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 3c94705

Please sign in to comment.