Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

change how we handle unions of missings and other types in unitary functions #53616

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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