Skip to content

Commit

Permalink
change how we handle unions of missings and other types in unitary fu…
Browse files Browse the repository at this point in the history
…nctions
  • Loading branch information
oxinabox committed Mar 6, 2024
1 parent 90d84d4 commit 0f4bdff
Showing 1 changed file with 6 additions and 12 deletions.
18 changes: 6 additions & 12 deletions base/missing.jl
Original file line number Diff line number Diff line change
Expand Up @@ -100,19 +100,13 @@ for f in (:(!), :(~), :(+), :(-), :(*), :(&), :(|), :(xor),
:(real), :(imag), :(sign), :(inv))
@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)
end
for f in (:zero, :one, :oneunit)
@eval ($f)(::Type{Any}) = throw(MethodError($f, (Any,))) # To prevent StackOverflowError
@eval ($f)(::Type{T}) where {T>:Missing} = $f(nonmissingtype_checked(T))
end
for f in (:(Base.float), :(Base.complex))
@eval $f(::Type{Missing}) = Missing
@eval function $f(::Type{Union{T, Missing}}) where T
T === Any && throw(MethodError($f, (Any,))) # To prevent StackOverflowError
Union{$f(T), Missing}
end
for f in (:float, :complex)
@eval ($f)(::Type{Any}) = throw(MethodError($f, (Any,))) # To prevent StackOverflowError
@eval ($f)(::Type{T}) where {T>:Missing} = Union{$f(nonmissingtype_checked(T)), Missing}
end

# Binary operators/functions
Expand Down

0 comments on commit 0f4bdff

Please sign in to comment.