Skip to content

Commit

Permalink
Support zero et al on ::Type{Missing}
Browse files Browse the repository at this point in the history
  • Loading branch information
iamed2 authored and Keno committed Mar 10, 2019
1 parent 60457de commit d2a54ca
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 0 deletions.
1 change: 1 addition & 0 deletions base/missing.jl
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ for f in (:(!), :(~), :(+), :(-), :(zero), :(one), :(oneunit),
@eval ($f)(::Missing) = missing
end
for f in (:(Base.zero), :(Base.one), :(Base.oneunit))
@eval ($f)(::Type{Missing}) = missing
@eval function $(f)(::Type{Union{T, Missing}}) where T
T === Any && throw(MethodError($f, (Any,))) # To prevent StackOverflowError
$f(T)
Expand Down
4 changes: 4 additions & 0 deletions test/missing.jl
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,10 @@ Base.one(::Type{Unit}) = 1
@test oneunit(Union{T, Missing}) === T(1)
end

@test zero(Missing) === missing
@test one(Missing) === missing
@test oneunit(Missing) === missing

@test_throws MethodError zero(Any)
@test_throws MethodError one(Any)
@test_throws MethodError oneunit(Any)
Expand Down

0 comments on commit d2a54ca

Please sign in to comment.