Skip to content

Commit db0b126

Browse files
SamuelBadrKristofferC
authored andcommitted
Allow showing of StepRangLen{T} with generic T (#49516)
(cherry picked from commit ee95843)
1 parent e59f589 commit db0b126

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

base/range.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1093,7 +1093,7 @@ show(io::IO, r::AbstractRange) = print(io, repr(first(r)), ':', repr(step(r)), '
10931093
show(io::IO, r::UnitRange) = print(io, repr(first(r)), ':', repr(last(r)))
10941094
show(io::IO, r::OneTo) = print(io, "Base.OneTo(", r.stop, ")")
10951095
function show(io::IO, r::StepRangeLen)
1096-
if step(r) != 0
1096+
if !iszero(step(r))
10971097
print(io, repr(first(r)), ':', repr(step(r)), ':', repr(last(r)))
10981098
else
10991099
# ugly temporary printing, to avoid 0:0:0 etc.

test/ranges.jl

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2392,3 +2392,16 @@ end
23922392
@test test_firstindex(StepRange{Union{Int64,Int128},Int}(Int64(1), 1, Int128(1)))
23932393
@test test_firstindex(StepRange{Union{Int64,Int128},Int}(Int64(1), 1, Int128(0)))
23942394
end
2395+
2396+
@testset "PR 49516" begin
2397+
struct PR49516 <: Signed
2398+
n::Int
2399+
end
2400+
PR49516(f::PR49516) = f
2401+
Base.:*(x::Integer, f::PR49516) = PR49516(*(x, f.n))
2402+
Base.:+(f1::PR49516, f2::PR49516) = PR49516(+(f1.n, f2.n))
2403+
Base.show(io::IO, f::PR49516) = print(io, "PR49516(", f.n, ")")
2404+
2405+
srl = StepRangeLen(PR49516(1), PR49516(2), 10)
2406+
@test sprint(show, srl) == "PR49516(1):PR49516(2):PR49516(19)"
2407+
end

0 commit comments

Comments
 (0)