Skip to content

Commit

Permalink
Merge pull request JuliaLang#17534 from JuliaLang/yyc/tests/show
Browse files Browse the repository at this point in the history
Add fallback method to `directsubtype` to handle `TypeVar`
  • Loading branch information
vtjnash authored Jul 21, 2016
2 parents c8f0d05 + efb3d08 commit 1ff1cbb
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
8 changes: 5 additions & 3 deletions base/show.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1174,6 +1174,8 @@ end
directsubtype(a::DataType, b::DataType) = supertype(a).name === b.name
directsubtype(a::TypeConstructor, b::DataType) = directsubtype(a.body, b)
directsubtype(a::Union, b::DataType) = any(t->directsubtype(t, b), a.types)
# Fallback to handle TypeVar's
directsubtype(a, b::DataType) = false
function dumpsubtypes(io::IO, x::DataType, m::Module, n::Int, indent)
for s in names(m, true)
if isdefined(m, s) && !isdeprecated(m, s)
Expand All @@ -1183,15 +1185,15 @@ function dumpsubtypes(io::IO, x::DataType, m::Module, n::Int, indent)
elseif isa(t, Module) && module_name(t) === s && module_parent(t) === m
# recurse into primary module bindings
dumpsubtypes(io, x, t, n, indent)
elseif isa(t, TypeConstructor) && directsubtype(t, x)
elseif isa(t, TypeConstructor) && directsubtype(t::TypeConstructor, x)
println(io)
print(io, indent, " ", m, ".", s)
isempty(t.parameters) || print(io, "{", join(t.parameters, ","), "}")
print(io, " = ", t)
elseif isa(t, Union) && directsubtype(t, x)
elseif isa(t, Union) && directsubtype(t::Union, x)
println(io)
print(io, indent, " ", m, ".", s, " = ", t)
elseif isa(t, DataType) && directsubtype(t, x)
elseif isa(t, DataType) && directsubtype(t::DataType, x)
println(io)
if t.name.module !== m || t.name.name != s
# aliases to types
Expand Down
2 changes: 2 additions & 0 deletions test/show.jl
Original file line number Diff line number Diff line change
Expand Up @@ -512,6 +512,8 @@ end
let repr = sprint(dump, Int64)
@test repr == "Int64 <: Signed\n"
end
# Make sure a `TypeVar` in a `Union` doesn't break subtype dump.
typealias BreakDump17529{T} Union{T,Void}
let repr = sprint(dump, Any)
@test length(repr) > 100000
@test ismatch(r"^Any\n [^ \t\n]", repr)
Expand Down

0 comments on commit 1ff1cbb

Please sign in to comment.