Skip to content

Commit

Permalink
fix printing of pairs containing array (fix #26256)
Browse files Browse the repository at this point in the history
  • Loading branch information
rfourquet committed Mar 24, 2018
1 parent 78c7d87 commit ef8e944
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
8 changes: 6 additions & 2 deletions base/show.jl
Original file line number Diff line number Diff line change
Expand Up @@ -577,12 +577,16 @@ function show(io::IO, p::Pair)
iocompact = IOContext(io, :compact => get(io, :compact, true))
has_tight_type(p) || return show_default(iocompact, p)

typeinfo = get(io, :typeinfo, Any)
typeinfos = typeinfo <: Pair ?
(fieldtype(typeinfo, 1), fieldtype(typeinfo, 2)) : (Any, Any)

isdelimited(iocompact, p.first) || print(io, "(")
show(iocompact, p.first)
show(IOContext(iocompact, :typeinfo => typeinfos[1]), p.first)
isdelimited(iocompact, p.first) || print(io, ")")
print(io, compact ? "=>" : " => ")
isdelimited(iocompact, p.second) || print(io, "(")
show(iocompact, p.second)
show(IOContext(iocompact, :typeinfo => typeinfos[2]), p.second)
isdelimited(iocompact, p.second) || print(io, ")")
nothing
end
Expand Down
3 changes: 3 additions & 0 deletions test/show.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1136,6 +1136,9 @@ end

# issue #25857
@test repr([(1,),(1,2),(1,2,3)]) == "Tuple{$Int,Vararg{$Int,N} where N}[(1,), (1, 2), (1, 2, 3)]"

# issue #26256
@test replstr([:A => [1]]) == "1-element Array{Pair{Symbol,Array{$Int,1}},1}:\n :A => [1]"
end

@testset "#14684: `display` should print associative types in full" begin
Expand Down

0 comments on commit ef8e944

Please sign in to comment.