Skip to content

Commit

Permalink
Create show_supertypes
Browse files Browse the repository at this point in the history
  • Loading branch information
omus committed Apr 19, 2017
1 parent ceccddf commit 992c442
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
10 changes: 10 additions & 0 deletions base/show.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions test/show.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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"

0 comments on commit 992c442

Please sign in to comment.