Skip to content

Commit 6a4dc3b

Browse files
authored
fix :typeinfo with views (closes #25038) (#25040)
1 parent f1baa90 commit 6a4dc3b

File tree

2 files changed

+12
-4
lines changed

2 files changed

+12
-4
lines changed

base/arrayshow.jl

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -321,10 +321,6 @@ function _display(io::IO, X::AbstractArray)
321321
# override usual show method for Vector{Method}: don't abbreviate long lists
322322
io = IOContext(io, :limit => false)
323323
end
324-
# we assume this function is always called from top-level, i.e. that it's not nested
325-
# within another "show" method; hence we always print the summary, without
326-
# checking for current :typeinfo (this could be changed in the future)
327-
io = IOContext(io, :typeinfo => eltype(X))
328324

329325
# 1) print summary info
330326
summary(io, X)
@@ -336,6 +332,15 @@ function _display(io::IO, X::AbstractArray)
336332
println(io)
337333
end
338334

335+
# 2) update typeinfo
336+
#
337+
# it must come after printing the summary, which can exploit :typeinfo itself
338+
# (e.g. views)
339+
# we assume this function is always called from top-level, i.e. that it's not nested
340+
# within another "show" method; hence we always print the summary, without
341+
# checking for current :typeinfo (this could be changed in the future)
342+
io = IOContext(io, :typeinfo => eltype(X))
343+
339344
# 2) show actual content
340345
print_array(io, X)
341346
end

test/show.jl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1041,4 +1041,7 @@ end
10411041
# from eltype(x), so this must also be printed
10421042
@test replstr(x) == "1-element Array{Any,1}:\n Any[Any[1]]"
10431043
end
1044+
# Issue #25038
1045+
A = [0.0, 1.0]
1046+
@test replstr(view(A, [1], :)) == "1×1 view(::Array{Float64,2}, [1], :) with eltype Float64:\n 0.0"
10441047
end

0 commit comments

Comments
 (0)