Skip to content

Commit

Permalink
Fix dump in the presence of nothing
Browse files Browse the repository at this point in the history
Currently anything that's `dump`ed that contains `nothing` will error,
since there's no logic in place for handling `nothing` in `dump` after
PR #27829.
  • Loading branch information
ararslan committed Jul 8, 2018
1 parent b6f9244 commit a349438
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
11 changes: 6 additions & 5 deletions base/show.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1613,11 +1613,12 @@ function dump(io::IOContext, @nospecialize(x), n::Int, indent)
nothing
end

dump(io::IOContext, x::Module, n::Int, indent) = print(io, "Module ", x)
dump(io::IOContext, x::String, n::Int, indent) = (print(io, "String "); show(io, x))
dump(io::IOContext, x::Symbol, n::Int, indent) = print(io, typeof(x), " ", x)
dump(io::IOContext, x::Union, n::Int, indent) = print(io, x)
dump(io::IOContext, x::Ptr, n::Int, indent) = print(io, x)
dump(io::IOContext, x::Module, n::Int, indent) = print(io, "Module ", x)
dump(io::IOContext, x::String, n::Int, indent) = (print(io, "String "); show(io, x))
dump(io::IOContext, x::Symbol, n::Int, indent) = print(io, typeof(x), " ", x)
dump(io::IOContext, x::Union, n::Int, indent) = print(io, x)
dump(io::IOContext, x::Ptr, n::Int, indent) = print(io, x)
dump(io::IOContext, x::Nothing, n::Int, indent) = show(io, x)

function dump_elts(io::IOContext, x::Array, n::Int, indent, i0, i1)
for i in i0:i1
Expand Down
3 changes: 3 additions & 0 deletions test/show.jl
Original file line number Diff line number Diff line change
Expand Up @@ -820,6 +820,9 @@ end
let repr = sprint(dump, Test)
@test repr == "Module Test\n"
end
let repr = sprint(dump, nothing)
@test repr == "nothing\n"
end
let a = Vector{Any}(undef, 10000)
a[2] = "elemA"
a[4] = "elemB"
Expand Down

0 comments on commit a349438

Please sign in to comment.