Skip to content

Commit ee95843

Browse files
authored
Allow showing of StepRangLen{T} with generic T (#49516)
1 parent ad939df commit ee95843

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
@@ -1101,7 +1101,7 @@ show(io::IO, r::AbstractRange) = print(io, repr(first(r)), ':', repr(step(r)), '
11011101
show(io::IO, r::UnitRange) = print(io, repr(first(r)), ':', repr(last(r)))
11021102
show(io::IO, r::OneTo) = print(io, "Base.OneTo(", r.stop, ")")
11031103
function show(io::IO, r::StepRangeLen)
1104-
if step(r) != 0
1104+
if !iszero(step(r))
11051105
print(io, repr(first(r)), ':', repr(step(r)), ':', repr(last(r)))
11061106
else
11071107
# 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
@@ -2441,6 +2441,19 @@ end
24412441
@test test_firstindex(StepRange{Union{Int64,Int128},Int}(Int64(1), 1, Int128(0)))
24422442
end
24432443

2444+
@testset "PR 49516" begin
2445+
struct PR49516 <: Signed
2446+
n::Int
2447+
end
2448+
PR49516(f::PR49516) = f
2449+
Base.:*(x::Integer, f::PR49516) = PR49516(*(x, f.n))
2450+
Base.:+(f1::PR49516, f2::PR49516) = PR49516(+(f1.n, f2.n))
2451+
Base.show(io::IO, f::PR49516) = print(io, "PR49516(", f.n, ")")
2452+
2453+
srl = StepRangeLen(PR49516(1), PR49516(2), 10)
2454+
@test sprint(show, srl) == "PR49516(1):PR49516(2):PR49516(19)"
2455+
end
2456+
24442457
@testset "Inline StepRange Construction #49270" begin
24452458
x = rand(Float32, 80)
24462459
a = rand(round(Int, length(x) / 2):length(x), 10^6)

0 commit comments

Comments
 (0)