Skip to content

Commit 4fddcb1

Browse files
committed
add warning
1 parent df2f1f5 commit 4fddcb1

File tree

1 file changed

+11
-7
lines changed

1 file changed

+11
-7
lines changed

src/ranges.jl

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,16 @@
22
"""
33
OptionallyStaticUnitRange(start, stop, check_lower_bound=True(), check_upper_bound=True()) <: AbstractUnitRange{Int}
44
5-
Similar to `UnitRange` except each field may be an `Int` or `StaticInt`. An
6-
`OptionallyStaticUnitRange` is intended to be constructed internally from other valid
7-
indices. Therefore, users should not expect the same checks are used to ensure construction
8-
of a valid `OptionallyStaticUnitRange` as a `UnitRange`. `check_lower_bound` and
9-
`check_upper_bound` determine whether `start` and `stop` are bounds checked when
10-
`OptionallyStaticUnitRange` is used as an index.
5+
Similar to `UnitRange` except each field may be an `Int` or `StaticInt`. `check_lower_bound`
6+
and `check_upper_bound` determine whether `start` and `stop` are bounds checked when
7+
`OptionallyStaticUnitRange` is used as an index. This type is intended to be constructed
8+
internally from other valid indices. Therefore, users should not expect the same checks are
9+
used to ensure construction of a valid `OptionallyStaticUnitRange` as a `UnitRange`.
10+
11+
!!! warning
12+
13+
Manually setting `check_lower_bound` and `check_upper_bound` to `False()` has similar
14+
behavior as `@inbounds` and may result in incorrect results/crashes/corruption.
1115
"""
1216
struct OptionallyStaticUnitRange{F<:CanonicalInt,L<:CanonicalInt,CLB<:Union{False,True},CUB<:Union{False,True}} <: AbstractUnitRange{Int}
1317
start::F
@@ -157,7 +161,7 @@ ArrayInterfaceCore.known_last(::Type{<:OptionallyStaticStepRange{<:Any,<:Any,Sta
157161
return known_first(r)
158162
end
159163
end
160-
function Base.step(r::OptionallyStaticStepRange)::Int
164+
@inline function Base.step(r::OptionallyStaticStepRange)::Int
161165
if known_step(r) === nothing
162166
return getfield(r, :step)
163167
else

0 commit comments

Comments
 (0)