diff --git a/base/show.jl b/base/show.jl index fc81db8fb4018..1325c40a90cc8 100644 --- a/base/show.jl +++ b/base/show.jl @@ -236,6 +236,16 @@ function show_datatype(io::IO, x::DataType) end end +function show_supertypes(io::IO, typ::DataType) + print(io, typ) + while typ != Any + typ = supertype(typ) + print(io, " <: ", typ) + end +end + +show_supertypes(typ::DataType) = show_supertypes(STDOUT, typ) + macro show(exs...) blk = Expr(:block) for ex in exs diff --git a/test/show.jl b/test/show.jl index e70904452b64b..fed4932db709b 100644 --- a/test/show.jl +++ b/test/show.jl @@ -670,3 +670,6 @@ let m = which(T20332{Int}(), (Int,)), end @test sprint(show, Main) == "Main" + +@test sprint(show_supertypes, Int64) == "Int64 <: Signed <: Integer <: Real <: Number <: Any" +@test sprint(show_supertypes, Vector{String}) == "Array{String,1} <: DenseArray{String,1} <: AbstractArray{String,1} <: Any"