Skip to content

Commit 483b637

Browse files
authored
fix #37401, displaying Enum in the repl (#37404)
1 parent b365157 commit 483b637

File tree

2 files changed

+21
-7
lines changed

2 files changed

+21
-7
lines changed

base/Enums.jl

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -47,13 +47,17 @@ function Base.show(io::IO, ::MIME"text/plain", x::Enum)
4747
show(io, Integer(x))
4848
end
4949

50-
function Base.show(io::IO, ::MIME"text/plain", t::Type{<:Enum})
51-
print(io, "Enum ")
52-
Base.show_datatype(io, t)
53-
print(io, ":")
54-
for x in instances(t)
55-
print(io, "\n", Symbol(x), " = ")
56-
show(io, Integer(x))
50+
function Base.show(io::IO, m::MIME"text/plain", t::Type{<:Enum})
51+
if isconcretetype(t)
52+
print(io, "Enum ")
53+
Base.show_datatype(io, t)
54+
print(io, ":")
55+
for x in instances(t)
56+
print(io, "\n", Symbol(x), " = ")
57+
show(io, Integer(x))
58+
end
59+
else
60+
invoke(show, Tuple{IO, MIME"text/plain", Type}, io, m, t)
5761
end
5862
end
5963

test/enums.jl

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,3 +200,13 @@ end
200200
alphabet_z = 26
201201
end
202202
@test alphabet_z == Alphabet(26)
203+
204+
let b = IOBuffer()
205+
show(b, MIME"text/plain"(), Enum)
206+
@test String(take!(b)) == "Enum"
207+
b = IOBuffer()
208+
show(b, MIME"text/plain"(), Union{Alphabet, BritishFood})
209+
str = String(take!(b))
210+
p = string(@__MODULE__)
211+
@test str == "Union{$p.Alphabet, $p.BritishFood}" || str == "Union{$p.BritishFood, $p.Alphabet}"
212+
end

0 commit comments

Comments
 (0)