julia> convert(Missing, 5)
ERROR: MethodError: convert(::Type{Union{}}, ::Int64) is ambiguous. Candidates:
convert(::Type{Union{}}, x) in Base at essentials.jl:166
convert(::Type{T}, x::Number) where T<:Number in Base at number.jl:7
convert(::Type{T}, arg) where T<:VecElement in Base at baseext.jl:8
convert(::Type{T}, x::Number) where T<:AbstractChar in Base at char.jl:179
Possible fix, define
convert(::Type{Union{}}, ::Number)
Stacktrace:
[1] convert(::Type{Missing}, ::Int64) at .\missing.jl:69
[2] top-level scope at REPL[240]:1
I saw this too a while ago and I remember thinking that the
convert(::Type{T}, arg) where T<:VecElement in Base at baseext.jl:8
seems kinda fishy. It feels like it could just be removed.
Why there is no convert(::Type{Missing}, arg) with some fancy error like error("haha, forget it (pun intended)") if !ismissing(arg)? /sarcasm:off
Well, my sarcasm and pun (convert to missing <=> forget) feels a bit displaced now, sorry for that. What I meant, was, why there is no specialized version for convert(::Type{Missing}, x)? Aka, why is convert to Missing the same as a convert to Union{}?
I see two solutions:
convert(::Type{Missing}, x) = missing
convert(::Type{Missing}, x) = throw(MethodError(convert, (Missing, x)))
Which do we want?
Surely not the first? 馃槹