Skip to content

Commit 9c4541b

Browse files
authored
Specialize 2-arg show for LinearIndices (JuliaLang#56482)
After this, ```julia julia> l = LinearIndices((1:3, 1:4)); julia> show(l) LinearIndices((1:3, 1:4)) ``` The printed form is a valid constructor.
1 parent bfcd3e9 commit 9c4541b

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

base/indices.jl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -576,3 +576,7 @@ first(iter::LinearIndices) = 1
576576
first(iter::LinearIndices{1}) = (@inline; first(axes1(iter.indices[1])))
577577
last(iter::LinearIndices) = (@inline; length(iter))
578578
last(iter::LinearIndices{1}) = (@inline; last(axes1(iter.indices[1])))
579+
580+
function show(io::IO, iter::LinearIndices)
581+
print(io, "LinearIndices(", iter.indices, ")")
582+
end

test/abstractarray.jl

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -335,6 +335,15 @@ end
335335
R = LinearIndices((Base.IdentityUnitRange(0:1), 0:1))
336336
@test axes(R) == (Base.IdentityUnitRange(0:1), Base.OneTo(2))
337337
end
338+
339+
@testset "show" begin
340+
A = zeros(2,3)
341+
for B in (A, view(A, Base.IdentityUnitRange(2:4)))
342+
l = LinearIndices(B)
343+
s = sprint(show, l)
344+
@test s == "LinearIndices($(axes(B)))"
345+
end
346+
end
338347
end
339348

340349
@testset "copy for LinearIndices/CartesianIndices" begin

0 commit comments

Comments
 (0)