JuliaGraphics / Colors.jl

Color manipulation utilities for Julia
Other
203 stars 45 forks source link

Ambiguous show method for `Union{}[]` #526

Closed fonsp closed 4 months ago

fonsp commented 1 year ago

Base.show(::IO, ::MIME{Symbol("image/svg+xml")}, ::Vector{Union{}}) is ambiguous, which leads to display errors when:

  1. Your environment supports SVG display (like Pluto, VS Code, Jupyter)
  2. You imported the Colors.jl package
  3. You output the object Union{}[]
➜  ~ julia
               _
   _       _ _(_)_     |  Documentation: https://docs.julialang.org
  (_)     | (_) (_)    |
   _ _   _| |_  __ _   |  Type "?" for help, "]?" for Pkg help.
  | | | | | | |/ _` |  |
  | | |_| | | | (_| |  |  Version 1.8.0 (2022-08-17)
 _/ |\__'_|_|_|\__'_|  |  Official https://julialang.org/ release
|__/                   |

(@v1.8) pkg> activate --temp
  Activating new project at `/var/folders/v_/fhpj9jn151d4p9c2fdw2gv780000gn/T/jl_NNCbMf`

(jl_NNCbMf) pkg> add Colors
    Updating registry at `~/.julia/registries/General.toml`
   Resolving package versions...
    Updating `/private/var/folders/v_/fhpj9jn151d4p9c2fdw2gv780000gn/T/jl_NNCbMf/Project.toml`
  [5ae59095] + Colors v0.12.8
    Updating `/private/var/folders/v_/fhpj9jn151d4p9c2fdw2gv780000gn/T/jl_NNCbMf/Manifest.toml`
  [3da002f7] + ColorTypes v0.11.4
  [5ae59095] + Colors v0.12.8
  [53c48c17] + FixedPointNumbers v0.8.4
  [189a3867] + Reexport v1.2.2
  [56f22d72] + Artifacts
  [8f399da3] + Libdl
  [37e2e46d] + LinearAlgebra
  [9a3f8284] + Random
  [ea8e919c] + SHA v0.7.0
  [9e88b42a] + Serialization
  [2f01184e] + SparseArrays
  [10745b16] + Statistics
  [e66e0078] + CompilerSupportLibraries_jll v0.5.2+0
  [4536629a] + OpenBLAS_jll v0.3.20+0
  [8e850b90] + libblastrampoline_jll v5.1.1+0

julia> x = Union{}[]
Union{}[]

julia> using Colors

julia> show(stdout, MIME"image/svg+xml"(), x)
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/fons/.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/fons/.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[8]:1
fonsp commented 1 year ago

This could also be resolved by adding this to Colors.jl:

Base.showable(::MIME"image/svg+xml", ::Vector{Union{}}) = false
johnnychen94 commented 1 year ago

Hmmm, I'm not sure if Colors has the right to do this type piracy... Do you have any ideas on how to safely proceed this?

fonsp commented 1 year ago

That's true... not sure!