diff --git a/base/show.jl b/base/show.jl index 6db661879f791..6e9089f6a3b99 100644 --- a/base/show.jl +++ b/base/show.jl @@ -1345,11 +1345,11 @@ function show_delim_array(io::IO, itr::Union{AbstractArray,SimpleVector}, op, de x = itr[i] show(recur_io, x) end - i += 1 - if i > l + if i == l delim_one && first && print(io, delim) break end + i += 1 first = false print(io, delim) print(io, ' ') diff --git a/test/offsetarray.jl b/test/offsetarray.jl index c447c6d420f2a..ed9bf582e633b 100644 --- a/test/offsetarray.jl +++ b/test/offsetarray.jl @@ -863,3 +863,12 @@ end # this is fixed in #40038, so the evaluation of its CartesianIndices should work @test CartesianIndices(A) == CartesianIndices(B) end + +@testset "overflowing show" begin + A = OffsetArray(repeat([1], 1), typemax(Int)-1) + b = IOBuffer(maxsize=10) + show(b, A) + @test String(take!(b)) == "[1]" + show(b, (A, A)) + @test String(take!(b)) == "([1], [1])" +end