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 11, 2024
1 parent 26b3b5f commit 5d279b1
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 17 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
5 changes: 0 additions & 5 deletions test/ambiguous.jl
Original file line number Diff line number Diff line change
Expand Up @@ -351,11 +351,6 @@ end
pop!(need_to_handle_undef_sparam, which(Base._cat, Tuple{Any, AbstractArray}))
pop!(need_to_handle_undef_sparam, which(Base.byteenv, (Union{AbstractArray{Pair{T,V}, 1}, Tuple{Vararg{Pair{T,V}}}} where {T<:AbstractString,V},)))
pop!(need_to_handle_undef_sparam, which(Base.float, Tuple{AbstractArray{Union{Missing, T},N} where {T, N}}))
pop!(need_to_handle_undef_sparam, which(Base.float, Tuple{Type{Union{Missing, T}} where T}))
pop!(need_to_handle_undef_sparam, which(Base.complex, Tuple{Type{Union{Missing, T}} where T}))
pop!(need_to_handle_undef_sparam, which(Base.zero, Tuple{Type{Union{Missing, T}} where T}))
pop!(need_to_handle_undef_sparam, which(Base.one, Tuple{Type{Union{Missing, T}} where T}))
pop!(need_to_handle_undef_sparam, which(Base.oneunit, Tuple{Type{Union{Missing, T}} where T}))
@test isempty(need_to_handle_undef_sparam)
end
end
Expand Down

0 comments on commit 5d279b1

Please sign in to comment.