close
The Wayback Machine - https://web.archive.org/web/20210705013754/https://github.com/JuliaLang/julia/issues/40951
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

Better error message for convert(Type{Union{}}, ...) #40951

Open
eschnett opened this issue May 26, 2021 · 7 comments
Open

Better error message for convert(Type{Union{}}, ...) #40951

eschnett opened this issue May 26, 2021 · 7 comments

Comments

@eschnett
Copy link
Contributor

@eschnett eschnett commented May 26, 2021

I received this error message:

  MethodError: convert(::Type{Union{}}, ::Vector{Float32}) is ambiguous. Candidates:
    convert(::Type{T}, a::AbstractArray) where T<:Array in Base at array.jl:532
    convert(T::Type{var"#s79"} where var"#s79"<:BitArray, a::AbstractArray) in Base at bitarray.jl:577
    convert(T::Type{var"#s832"} where var"#s832"<:SparseArrays.SparseVector, m::AbstractVector{T} where T) in SparseArrays at /Users/eschnett/julia-1.6/share/julia/stdlib/v1.6/SparseArrays/src/sparsevector.jl:453
    convert(T::Type{var"#s832"} where var"#s832"<:SharedArrays.SharedArray, a::Array) in SharedArrays at /Users/eschnett/julia-1.6/share/julia/stdlib/v1.6/SharedArrays/src/SharedArrays.jl:377
    convert(::Type{Union{}}, x) in Base at essentials.jl:203
    convert(::Type{T}, arg) where T<:VecElement in Base at baseext.jl:8
  Possible fix, define
    convert(::Type{Union{}}, ::Vector{T} where T)

This is a confusing error message. Would it be possible to catch this as a special case in the definition of convert, and emit an error such as "Converting to Union{}" does not make sense; check your call site"?

@JeffBezanson
Copy link
Member

@JeffBezanson JeffBezanson commented May 26, 2021

Yes, we already have a function show_convert_error to give better printing of method errors involving convert. This case can be added there.

@jakobnissen
Copy link
Contributor

@jakobnissen jakobnissen commented May 27, 2021

Ref #36706

@sanjibansg
Copy link
Contributor

@sanjibansg sanjibansg commented May 27, 2021

I would like to contribute to this issue, will be grateful for guidance to approach this. @JeffBezanson @eschnett @jakobnissen

@ArunSanganal
Copy link
Contributor

@ArunSanganal ArunSanganal commented Jun 2, 2021

@kahanikaar are you working on this issue?

@Pramodh-G
Copy link
Contributor

@Pramodh-G Pramodh-G commented Jun 16, 2021

Hi @eschnett, thanks for filing the issue. Could you please help me by providing a MWE to reproduce it? It would help me understand what's going on behind the scenes here.

@eschnett
Copy link
Contributor Author

@eschnett eschnett commented Jun 16, 2021

Try this:

convert(Union{}, Float32[])
@ArunSanganal
Copy link
Contributor

@ArunSanganal ArunSanganal commented Jun 20, 2021

Not quite sure but does fixing this issue start with modifying this?

convert(::Type{Union{}}, x) = throw(MethodError(convert, (Union{}, x)))

I am kinda new to error handling so any help would be appreciated. Logic says whenever this is encountered, we need to redirect it to show_convert_error function as @JeffBezanson mentioned.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
6 participants