From ef8e944979e341edbdfcde14faf5b53dfdf44010 Mon Sep 17 00:00:00 2001 From: Rafael Fourquet Date: Sat, 24 Mar 2018 07:47:06 +0100 Subject: [PATCH] fix printing of pairs containing array (fix #26256) --- base/show.jl | 8 ++++++-- test/show.jl | 3 +++ 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/base/show.jl b/base/show.jl index c51d5b279c2d3d..20063e86bcb11c 100644 --- a/base/show.jl +++ b/base/show.jl @@ -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 diff --git a/test/show.jl b/test/show.jl index 307f576a7fb946..eda8562f057bea 100644 --- a/test/show.jl +++ b/test/show.jl @@ -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