Skip to content

Commit

Permalink
step(::AbstractUnitRange{Bool}) should return Bool (#56405)
Browse files Browse the repository at this point in the history
The issue was introduced by #27302 , as
```julia
julia> true-false
1
```

By definitions below, `AbstractUnitRange{Bool} <: OrdinalRange{Bool,
Bool}` whose step type is `Bool`.


https://github.com/JuliaLang/julia/blob/da74ef1933b12410b217748e0f7fbcbe52e10d29/base/range.jl#L280-L299

---------

Co-authored-by: Matt Bauman <[email protected]>
Co-authored-by: Matt Bauman <[email protected]>
  • Loading branch information
3 people authored Nov 6, 2024
1 parent d3130ae commit 80a2791
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 0 deletions.
1 change: 1 addition & 0 deletions base/range.jl
Original file line number Diff line number Diff line change
Expand Up @@ -711,6 +711,7 @@ julia> step(range(2.5, stop=10.9, length=85))
"""
step(r::StepRange) = r.step
step(r::AbstractUnitRange{T}) where {T} = oneunit(T) - zero(T)
step(r::AbstractUnitRange{Bool}) = true
step(r::StepRangeLen) = r.step
step(r::StepRangeLen{T}) where {T<:AbstractFloat} = T(r.step)
step(r::LinRange) = (last(r)-first(r))/r.lendiv
Expand Down
4 changes: 4 additions & 0 deletions test/ranges.jl
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,10 @@ using .Main.OffsetArrays

unitrangeerrstr = "promotion of types Char and Char failed to change any arguments"
@test_throws unitrangeerrstr UnitRange('a', 'b')

@test step(false:true) === true # PR 56405
@test eltype((false:true) + (Int8(0):Int8(1))) === Int8
@test eltype((false:true:true) + (Int8(0):Int8(1))) === Int8
end

using Dates, Random
Expand Down

0 comments on commit 80a2791

Please sign in to comment.