Skip to content

Commit 0f4bdff

Browse files
committed
change how we handle unions of missings and other types in unitary functions
1 parent 90d84d4 commit 0f4bdff

File tree

1 file changed

+6
-12
lines changed

1 file changed

+6
-12
lines changed

base/missing.jl

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -100,19 +100,13 @@ for f in (:(!), :(~), :(+), :(-), :(*), :(&), :(|), :(xor),
100100
:(real), :(imag), :(sign), :(inv))
101101
@eval ($f)(::Missing) = missing
102102
end
103-
for f in (:(Base.zero), :(Base.one), :(Base.oneunit))
104-
@eval ($f)(::Type{Missing}) = missing
105-
@eval function $(f)(::Type{Union{T, Missing}}) where T
106-
T === Any && throw(MethodError($f, (Any,))) # To prevent StackOverflowError
107-
$f(T)
108-
end
103+
for f in (:zero, :one, :oneunit)
104+
@eval ($f)(::Type{Any}) = throw(MethodError($f, (Any,))) # To prevent StackOverflowError
105+
@eval ($f)(::Type{T}) where {T>:Missing} = $f(nonmissingtype_checked(T))
109106
end
110-
for f in (:(Base.float), :(Base.complex))
111-
@eval $f(::Type{Missing}) = Missing
112-
@eval function $f(::Type{Union{T, Missing}}) where T
113-
T === Any && throw(MethodError($f, (Any,))) # To prevent StackOverflowError
114-
Union{$f(T), Missing}
115-
end
107+
for f in (:float, :complex)
108+
@eval ($f)(::Type{Any}) = throw(MethodError($f, (Any,))) # To prevent StackOverflowError
109+
@eval ($f)(::Type{T}) where {T>:Missing} = Union{$f(nonmissingtype_checked(T)), Missing}
116110
end
117111

118112
# Binary operators/functions

0 commit comments

Comments
 (0)