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

Base.show(io, ::MIME"image/svg+xml", ::Vector{Union{}}) is ambiguous #47840

Closed
Roger-luo opened this issue Dec 8, 2022 · 2 comments
Closed

Comments

@Roger-luo
Copy link
Contributor

In Colors, this is overloaded for the Color type, but because Union{} <: Color, this will be ambiguous, e.g

using Colors
st = Union{}[]
Base.show(stdout, MIME"image/svg+xml"(), st)

gives

julia> Base.show(stdout, MIME"image/svg+xml"(), st)
ERROR: MethodError: show(::Base.TTY, ::MIME{Symbol("image/svg+xml")}, ::Vector{Union{}}) is ambiguous. Candidates:
  show(io::IO, mime::MIME{Symbol("image/svg+xml")}, cs::AbstractVector{T}; max_swatches) where T<:TransparentColor in Colors at /Users/roger/.julia/packages/Colors/yDxFN/src/display.jl:41
  show(io::IO, mime::MIME{Symbol("image/svg+xml")}, cs::AbstractVector{T}; max_swatches) where T<:Color in Colors at /Users/roger/.julia/packages/Colors/yDxFN/src/display.jl:35
Possible fix, define
  show(::IO, ::MIME{Symbol("image/svg+xml")}, ::AbstractVector{Union{}})
Stacktrace:
 [1] top-level scope
   @ REPL[11]:1

because show(::IO, ::MIME{Symbol("image/svg+xml")}, ::AbstractVector{Union{}}) only relats to types in Base, so I think it should be defined here, but the questions how should we define it?

@thofma
Copy link
Contributor

thofma commented Dec 9, 2022

One can construct infinitely many ambiguities, which, following this logic, should be resolved in Base:

julia> struct MyType1 end

julia> struct MyType2 end

julia> Base.:(+)(x::Vector{T}, y::Vector{T}) where {T <: MyType1} = x .+ y

julia> Base.:(+)(x::Vector{T}, y::Vector{T}) where {T <: MyType2} = x .+ y

julia> Union{}[] + Union{}[]
ERROR: MethodError: +(::Vector{Union{}}, ::Vector{Union{}}) is ambiguous. Candidates:
  +(x::Vector{T}, y::Vector{T}) where T<:MyType1 in Main at REPL[3]:1
  +(x::Vector{T}, y::Vector{T}) where T<:MyType2 in Main at REPL[4]:1
Possible fix, define
  +(::Vector{Union{}}, ::Vector{Union{}})
Stacktrace:
 [1] top-level scope
   @ REPL[5]:1

I don't think adding random methods to Base is a solution that scales.

@simeonschaub
Copy link
Member

I have to agree. Defining methods for AbstractVector{<:T} is considered type piracy, so this needs to be fixed at a package level. See also #33780

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants