Project

General

Profile

Actions

Bug #20936

closed

Enumerator's #size returned by Range#reverse_each raises an exception for beginningless Range

Added by andrykonchin (Andrew Konchin) 13 days ago. Updated 12 days ago.

Status:
Closed
Assignee:
-
Target version:
-
[ruby-core:120138]

Description

(..3).reverse_each.size is supposed to return Infinity (at least it does so in Ruby 3.3). But in Ruby 3.4 preview it raises can't iterate from NilClass (TypeError) what seems a regression.

Ruby 3.3.5:

$ ruby -v -e 'p (..3).reverse_each.size'
ruby 3.3.5 (2024-09-03 revision ef084cc8f4) [x86_64-darwin23]
Infinity

$ ruby -v -e 'p (1..).reverse_each.size'
ruby 3.3.5 (2024-09-03 revision ef084cc8f4) [x86_64-darwin23]
Infinity

3.4.0dev:

$ ruby -v -e 'p (1..).reverse_each.size'
ruby 3.4.0dev (2024-12-09T08:00:19Z master 652b0c13a7) +PRISM [x86_64-darwin23]
Infinity

$ ruby -v -e 'p (..3).reverse_each.size'
ruby 3.4.0dev (2024-12-09T08:00:19Z master 652b0c13a7) +PRISM [x86_64-darwin23]
-e:1:in 'Enumerator#size': can't iterate from NilClass (TypeError)
	from -e:1:in '<main>'
Actions #1

Updated by andrykonchin (Andrew Konchin) 13 days ago

  • Subject changed from Enumerator#size returned by Range#reverse_each raises an exception to Enumerator's size returned by Range#reverse_each raises an exception
Actions #2

Updated by andrykonchin (Andrew Konchin) 13 days ago

  • Subject changed from Enumerator's size returned by Range#reverse_each raises an exception to Enumerator's #size returned by Range#reverse_each raises an exception
Actions #3

Updated by andrykonchin (Andrew Konchin) 13 days ago

  • Subject changed from Enumerator's #size returned by Range#reverse_each raises an exception to Enumerator's #size returned by Range#reverse_each raises an exception for beginningless Range

Updated by kyanagi (Kouhei Yanagita) 13 days ago

I made a pull request: https://github.com/ruby/ruby/pull/12301
Does this fix work?

Updated by andrykonchin (Andrew Konchin) 12 days ago

It works. Thank you!

Actions #6

Updated by kyanagi (Kouhei Yanagita) 12 days ago

  • Status changed from Open to Closed

Applied in changeset git|3422bfcab6bfdedd10e5c85f5fd6334387712bc6.


[Bug #20936] Fix #size for Range#reverse_each

Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0Like0Like0