Skip to content

Commit

Permalink
Define round(::Type{>:Missing}, x) and similar functions (#25762)
Browse files Browse the repository at this point in the history
We currently define round(::Type{>:Missing}, ::Missing), but not the corresponding method
for non-missing inputs was missing, making it basically useless.
  • Loading branch information
nalimilan authored Feb 3, 2018
1 parent 34b732b commit 97a1856
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
6 changes: 5 additions & 1 deletion base/missing.jl
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,11 @@ for f in (:(ceil), :(floor), :(round), :(trunc))
($f)(::Missing, digits::Integer=0, base::Integer=0) = missing
($f)(::Type{>:Missing}, ::Missing) = missing
($f)(::Type{T}, ::Missing) where {T} =
throw(MissingException("cannot convert a missing value to type $T"))
throw(MissingException("cannot convert a missing value to type $T: use Union{$T, Missing} instead"))
($f)(::Type{T}, x::Any) where {T>:Missing} = $f(nonmissingtype(T), x)
# to fix ambiguities
($f)(::Type{T}, x::Rational) where {T>:Missing} = $f(nonmissingtype(T), x)
($f)(::Type{T}, x::Rational{Bool}) where {T>:Missing} = $f(nonmissingtype(T), x)
end
end

Expand Down
1 change: 1 addition & 0 deletions test/missing.jl
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,7 @@ end
@test ismissing(f(missing, 1))
@test ismissing(f(missing, 1, 1))
@test ismissing(f(Union{Int, Missing}, missing))
@test f(Union{Int, Missing}, 1.0) === 1
@test_throws MissingException f(Int, missing)
end
end
Expand Down

0 comments on commit 97a1856

Please sign in to comment.