julia
julia copied to clipboard
Cases in with convert has dispatch ambiguity
We have the following behaviors:
julia> convert(Union{}, 1)
ERROR: MethodError: convert(::Type{Union{}}, ::Int64) is ambiguous. Candidates:
julia> convert(Missing, 1) # the same - falls back to the previous one internally
ERROR: MethodError: convert(::Type{Union{}}, ::Int64) is ambiguous. Candidates:
@vtjnash - I am pinging you as you have last changed the relevant convert
methods.
Ah, this case might need to be added explicitly to nonmissingtype_checked
?
This would solve convert(Missing, 1)
, but convert(Union{}, 1)
problem would still be present (probably no one in practice this will never happen, but just for completeness of definitions in Base I think it would be good to fix it).
Also the same problem as with nonmissingtype_checked
you mention is with nonnothingtype_checked
:
julia> Base.nonnothingtype_checked(Nothing)
Union{}
no, that is intentionally ambiguous, since it is often unavoidable by package authors
yep, that method should be updated to be the same also
The issue with convert(Missing, 1)
is still present on nightly even with nonmissingtype_checked
.
I think we should add:
convert(::Type{Missing}, ::Missing) = missing
convert(::Type{Missing}, ::T) where {T} = throw(ArgumentError("cannot convert value of type $T to `Missing`"))
Of course custom types could override this default conversion rule.
Yes, this issue is still open, and my comment above still relevant as a possible fix
Ah - you are right. I thought nonmissingtype_checked
was changed. Sorry for the confusion.
Label "types and dispatch" should be applied there