Skip to content

Conversation

headius
Copy link
Member

@headius headius commented Aug 10, 2025

Logic installed to prevent large ranges from manually iterating to calculate a count (79ee920) short-circuited the fallback on Enumerable#count logic. That broke count when passed a block (as described in #8955). Additionally, we did not handle the case where Range#count is passed an argument.

This PR fixes both cases and adds specs.

Block-receiving Range#count should always use Enumerable logic.

Also add single-arg form which falls back on Enumerable.

Fixes jruby#8955
These specs are lightly-modified versions of the same specs from
Enumerable#count, but those specs depend on the Enumerable having
multiple of the same value. A shared spec could probably be pulled
out.

See jruby#8955.
@headius headius added this to the JRuby 10.0.3.0 milestone Aug 10, 2025
@headius headius linked an issue Aug 10, 2025 that may be closed by this pull request
@headius headius merged commit be95012 into jruby:master Aug 10, 2025
73 checks passed
@headius headius deleted the range_count_block branch August 10, 2025 16:43
Copy link

@pboling pboling left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Range#count always returns size for Integer bounds
2 participants