Skip to content

Commit 9315ca0

Browse files
authored
fix :typeinfo with tuple elements (closes #25042) (#25043)
1 parent 9b8e651 commit 9315ca0

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

base/show.jl

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -491,14 +491,18 @@ function show_delim_array(io::IO, itr, op, delim, cl, delim_one, i1=1, n=typemax
491491
recur_io = IOContext(io, :SHOWN_SET => itr)
492492
state = start(itr)
493493
first = true
494+
i0 = i1-1
494495
while i1 > 1 && !done(itr, state)
495496
_, state = next(itr, state)
496497
i1 -= 1
497498
end
498499
if !done(itr, state)
500+
typeinfo = get(io, :typeinfo, Any)
499501
while true
500502
x, state = next(itr, state)
501-
show(recur_io, x)
503+
show(IOContext(recur_io, :typeinfo =>
504+
typeinfo <: Tuple ? typeinfo.parameters[i1+i0] : typeinfo),
505+
x)
502506
i1 += 1
503507
if done(itr, state) || i1 > n
504508
delim_one && first && print(io, delim)

test/show.jl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1042,6 +1042,9 @@ end
10421042
@test showstr([[Float16(1)]]) == "Array{Float16,1}[[1.0]]"
10431043
@test replstr(Real[Float16(1)]) == "1-element Array{Real,1}:\n Float16(1.0)"
10441044
@test replstr(Array{Real}[Real[1]]) == "1-element Array{Array{Real,N} where N,1}:\n [1]"
1045+
# printing tuples (Issue #25042)
1046+
@test replstr(fill((Int64(1), zeros(Float16, 3)), 1)) ==
1047+
"1-element Array{Tuple{Int64,Array{Float16,1}},1}:\n (1, [0.0, 0.0, 0.0])"
10451048
@testset "nested Any eltype" begin
10461049
x = Any[Any[Any[1]]]
10471050
# The element of x (i.e. x[1]) has an eltype which can't be deduced

0 commit comments

Comments
 (0)