Project

General

Profile

Actions

Bug #21152

closed

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

Added by andrykonchin (Andrew Konchin) about 1 month ago. Updated 18 days ago.

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

Description

I've noticed a change between 3.3 and 3.4 in a way how Range#reverse_each behaves:

Ruby 3.3:

Range.new("a", nil).size # => nil
Range.new(1, nil).size # => Infinity

Range.new("a", nil).reverse_each.size # => nil
Range.new(1, nil).reverse_each.size # => Infinity

Ruby 3.4

Range.new("a", nil).size # => nil
Range.new(1, nil).size # => Infinity

Range.new("a", nil).reverse_each.size # can't iterate from NilClass (TypeError)
Range.new(1, nil).reverse_each.size # can't iterate from NilClass (TypeError)

Updated by eileencodes (Eileen Uchitelle) about 1 month ago

This changed in https://github.com/ruby/ruby/pull/12301 to fix a similar bug.

Range.new(nil, "a").size also raises a TypeError when in 3.3 it didn't.

Updated by eileencodes (Eileen Uchitelle) about 1 month ago

In 3.3 each does raise with this example:

Range.new(nil,1).each do |x|
  p x
end

And reverse_each does not. It feels like to me that 3.4 is more correct than 3.3.

Updated by mame (Yusuke Endoh) 18 days ago

  • Status changed from Open to Closed

Discussed at the dev meeting, and @matz (Yukihiro Matsumoto) agreed with @eileencodes (Eileen Uchitelle) ; the behavior of Ruby 3.4 is better.

Actions

Also available in: Atom PDF

Like0
Like0Like0Like1