You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
There are 4 types in the standard library that define both #[]?(range : Range) and #[]?(start : Int, count : Int). When the start index is too small, the latter always returns nil, but the first may still raise IndexError nonetheless:
deffoo(x)
a =begin; x[-3, 2]?; rescue ex; ex; end
b =begin; x[-3..-2]?; rescue ex; ex; end
c =begin; x[3, 2]?; rescue ex; ex; end
d =begin; x[3..4]?; rescue ex; ex; end
{a, b, c, d}
end
foo([0, 0]) # => {nil, nil, nil, nil}
foo(Slice[0, 0]) # => {nil, #<IndexError:Index out of bounds>, nil, nil}
foo("00") # => {nil, nil, nil, nil}
foo("00".match!(/(.)/)) # => {nil, #<IndexError:Index out of bounds>, nil, nil}
This does not seem to be intended behavior; all kinds of out-of-range calls to #[]? should return nil, not just ones whose range start index is large enough.
(This does not concern with the definition of "out-of-bound" itself, which is currently different for Slice; what matters here is that #[] and #[]? agree on their notions of "out-of-bound".)
(The internal StringScanner::StringMatchData defines only the Range overload. It never raises IndexError.)
The text was updated successfully, but these errors were encountered:
There are 4 types in the standard library that define both
#[]?(range : Range)
and#[]?(start : Int, count : Int)
. When the start index is too small, the latter always returnsnil
, but the first may still raiseIndexError
nonetheless:This does not seem to be intended behavior; all kinds of out-of-range calls to
#[]?
should returnnil
, not just ones whose range start index is large enough.(This does not concern with the definition of "out-of-bound" itself, which is currently different for
Slice
; what matters here is that#[]
and#[]?
agree on their notions of "out-of-bound".)(The internal
StringScanner::StringMatchData
defines only theRange
overload. It never raisesIndexError
.)The text was updated successfully, but these errors were encountered: