@enum macro example fails due to ColorType.jl loaded

When running this Base.instances exemple code with Julia 1.2

julia> @enum Color red blue green
julia> instances(Color)
(red::Color = 0, blue::Color = 1, green::Color = 2)

I got the following error :

julia> @enum Color red blue green
ERROR: cannot assign a value to variable ColorTypes.Color from module Main
[1] top-level scope at Enums.jl:184

Surprised by a Base function documentation fail, as a double check, (even if the err message isn’t related to @enum), I did

julia> @enum Age young adult old
julia> instances(Age)
(young, adult, old)

julia> typeof(Color)

julia> instances(Color)
ERROR: MethodError: no method matching instances(::Type{Color})
Closest candidates are:
  instances(::Type{Base.MPFR.MPFRRoundingMode}) at Enums.jl:193
  instances(::Type{LibGit2.Consts.OBJECT}) at Enums.jl:193
  instances(::Type{LibGit2.Consts.DELTA_STATUS}) at Enums.jl:193
 [1] top-level scope at REPL[400]:1

So Color is part of the ColorsTypes hierarchy. So this must mean I am using the ColorType.jl , that I’ve must have loaded with some “using Pkg”, possibly Plots.

Finding the explanation for myself is good Julia experience, but still I feel it can be really confusing to get a documentation example fail for newcomers.

Should I open a issue in Julialang/julia to propose to get this example less prone to this kind of name clash error (using another @enum example) ?

1 Like

I think a PR to make the documentation example less likely to clash with widely used packages would be welcome.


@Chris_Foster Thanks for your input.
I’ll do it over the weekend.