From: "masasakano (Masa Sakano)" Date: 2022-08-30T19:51:21+00:00 Subject: [ruby-core:109793] [Ruby master Feature#18986] Raises Exception for Range#last(n) with Float::INFINITY Issue #18986 has been reported by masasakano (Masa Sakano). ---------------------------------------- Feature #18986: Raises Exception for Range#last(n) with Float::INFINITY https://bugs.ruby-lang.org/issues/18986 * Author: masasakano (Masa Sakano) * Status: Open * Priority: Normal ---------------------------------------- When a (Numeric) argument is given to `Range#last(n)` for a Range with `Float::INFINITY`, it runs into an infinite loop (see a small code snippet below). There is no use case for the feature as far as I can think of, and it is hard to detect. ```ruby (6..Float::INFINITY).last(1) # => infinite loop!! (6..).last(1) # cannot get the last element of endless range (RangeError) (-Float::INFINITY..4).last(1) # can't iterate from Float (TypeError) (..4).last(1) # can't iterate from Float (TypeError) ``` Let me suggest raising an Exception (maybe RangeError, in the same way as an endless Range) when `last(n)` is specified for a Range whose end value is `Float::INFINITY`. I note `(6..Float::INFINITY).to_a` has the same issue. -- https://bugs.ruby-lang.org/ Unsubscribe: