Skip to content

Commit

Permalink
fix :typeinfo with tuple elements (closes #25042) (#25043)
Browse files Browse the repository at this point in the history
  • Loading branch information
rfourquet authored Dec 15, 2017
1 parent 9b8e651 commit 9315ca0
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
6 changes: 5 additions & 1 deletion base/show.jl
Original file line number Diff line number Diff line change
Expand Up @@ -491,14 +491,18 @@ function show_delim_array(io::IO, itr, op, delim, cl, delim_one, i1=1, n=typemax
recur_io = IOContext(io, :SHOWN_SET => itr)
state = start(itr)
first = true
i0 = i1-1
while i1 > 1 && !done(itr, state)
_, state = next(itr, state)
i1 -= 1
end
if !done(itr, state)
typeinfo = get(io, :typeinfo, Any)
while true
x, state = next(itr, state)
show(recur_io, x)
show(IOContext(recur_io, :typeinfo =>
typeinfo <: Tuple ? typeinfo.parameters[i1+i0] : typeinfo),
x)
i1 += 1
if done(itr, state) || i1 > n
delim_one && first && print(io, delim)
Expand Down
3 changes: 3 additions & 0 deletions test/show.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1042,6 +1042,9 @@ end
@test showstr([[Float16(1)]]) == "Array{Float16,1}[[1.0]]"
@test replstr(Real[Float16(1)]) == "1-element Array{Real,1}:\n Float16(1.0)"
@test replstr(Array{Real}[Real[1]]) == "1-element Array{Array{Real,N} where N,1}:\n [1]"
# printing tuples (Issue #25042)
@test replstr(fill((Int64(1), zeros(Float16, 3)), 1)) ==
"1-element Array{Tuple{Int64,Array{Float16,1}},1}:\n (1, [0.0, 0.0, 0.0])"
@testset "nested Any eltype" begin
x = Any[Any[Any[1]]]
# The element of x (i.e. x[1]) has an eltype which can't be deduced
Expand Down

0 comments on commit 9315ca0

Please sign in to comment.