Skip to content

Commit 1ff1cbb

Browse files
authored
Merge pull request JuliaLang#17534 from JuliaLang/yyc/tests/show
Add fallback method to `directsubtype` to handle `TypeVar`
2 parents c8f0d05 + efb3d08 commit 1ff1cbb

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed

base/show.jl

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1174,6 +1174,8 @@ end
11741174
directsubtype(a::DataType, b::DataType) = supertype(a).name === b.name
11751175
directsubtype(a::TypeConstructor, b::DataType) = directsubtype(a.body, b)
11761176
directsubtype(a::Union, b::DataType) = any(t->directsubtype(t, b), a.types)
1177+
# Fallback to handle TypeVar's
1178+
directsubtype(a, b::DataType) = false
11771179
function dumpsubtypes(io::IO, x::DataType, m::Module, n::Int, indent)
11781180
for s in names(m, true)
11791181
if isdefined(m, s) && !isdeprecated(m, s)
@@ -1183,15 +1185,15 @@ function dumpsubtypes(io::IO, x::DataType, m::Module, n::Int, indent)
11831185
elseif isa(t, Module) && module_name(t) === s && module_parent(t) === m
11841186
# recurse into primary module bindings
11851187
dumpsubtypes(io, x, t, n, indent)
1186-
elseif isa(t, TypeConstructor) && directsubtype(t, x)
1188+
elseif isa(t, TypeConstructor) && directsubtype(t::TypeConstructor, x)
11871189
println(io)
11881190
print(io, indent, " ", m, ".", s)
11891191
isempty(t.parameters) || print(io, "{", join(t.parameters, ","), "}")
11901192
print(io, " = ", t)
1191-
elseif isa(t, Union) && directsubtype(t, x)
1193+
elseif isa(t, Union) && directsubtype(t::Union, x)
11921194
println(io)
11931195
print(io, indent, " ", m, ".", s, " = ", t)
1194-
elseif isa(t, DataType) && directsubtype(t, x)
1196+
elseif isa(t, DataType) && directsubtype(t::DataType, x)
11951197
println(io)
11961198
if t.name.module !== m || t.name.name != s
11971199
# aliases to types

test/show.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -512,6 +512,8 @@ end
512512
let repr = sprint(dump, Int64)
513513
@test repr == "Int64 <: Signed\n"
514514
end
515+
# Make sure a `TypeVar` in a `Union` doesn't break subtype dump.
516+
typealias BreakDump17529{T} Union{T,Void}
515517
let repr = sprint(dump, Any)
516518
@test length(repr) > 100000
517519
@test ismatch(r"^Any\n [^ \t\n]", repr)

0 commit comments

Comments
 (0)