Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

step(::AbstractUnitRange{Bool}) should return Bool #56405

Merged
merged 5 commits into from
Nov 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder why this definition is used here? The docstring of AbstractUnitRange states that the step is oneunit(T), which seems to differ from this definition.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ask #27302

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
putianyi889 marked this conversation as resolved.
Show resolved Hide resolved
@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