Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make Range#reverse_each to raise an exception if endless #5498

Merged

Conversation

kyanagi
Copy link
Contributor

@kyanagi kyanagi commented Jan 27, 2022

https://bugs.ruby-lang.org/issues/18551

Currently, Range#reverse_each for an endless range never returns.

% ruby -e '(1..).reverse_each { }'
# never return ...

(This is because Enumerable#reverse_each tries #to_a and #to_a for an endless range comes into an infinite loop.)

I think Range#reverse_each for an endless range should raise an exception, similar to Range#each for a beginless range.

% ruby -e '(..1).each { }' 
-e:1:in `each': can't iterate from NilClass (TypeError)
	from -e:1:in `<main>'

@kyanagi kyanagi force-pushed the endless_range_reverse_each_should_raise_an_exception branch from 8ba25f2 to bd33dca Compare October 27, 2023 12:44
@kyanagi kyanagi force-pushed the endless_range_reverse_each_should_raise_an_exception branch from bd33dca to fce952f Compare November 7, 2023 02:06
@mame mame force-pushed the endless_range_reverse_each_should_raise_an_exception branch from fce952f to 771df19 Compare November 28, 2023 05:47
@mame mame enabled auto-merge (rebase) November 28, 2023 05:49
@mame mame merged commit 1a16b6f into ruby:master Nov 28, 2023
96 of 98 checks passed
@kyanagi kyanagi deleted the endless_range_reverse_each_should_raise_an_exception branch November 28, 2023 07:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
2 participants