Skip to content

Range: iterate Symbol/other #succ ranges, and fix single-byte String ranges - #461

Merged
tannevaled merged 1 commit into
mainfrom
feat/cluster31
Aug 26, 2026
Merged

tannevaled merged 1 commit into
mainfrom
feat/cluster31

Conversation

@tannevaled

Copy link
Copy Markdown
Contributor

Range iteration (each/to_a/map/first/last/min/max/take/drop)
only understood Integer and String begins; a Symbol, Date, or any object with
#succ and #<=> raised can't iterate from …. A new vm.rangeElemsV
materialises a bounded range generically: Integer/String keep the fast path, a
Symbol walks like a String range and re-symbolises, and any other #succ-responder
is walked by #succ while #<=> has not passed end (iteration stops if #<=>
stops ordering the value, as MRI does). Range#each also gains the endless
Symbol/#succ form. Materialising an endless range still raises, and a begin
without #succ is a TypeError.

This exposed a pre-existing bug in strRangeElems: a single-byte..single-byte
String range was walked by #succ, so "A".."z" stopped at "Z" ("Z".succ is
"AA") instead of crossing the punctuation to "z". MRI iterates such a range by
byte value, so it now yields all 58 elements; multi-character ranges keep the
#succ-with-length-guard walk. This fixes String ranges and Symbol ranges alike.

Verified against ruby 4.0.6. Full package coverage stays at 100.0%.
Zero-regression rubyspec sweep; core/range/each_spec 7 → 8,
core/range/to_a_spec 5 → 6, and Symbol/String single-byte ranges are now
MRI-correct.

🤖 Generated with Claude Code

…ranges

Range iteration (each/to_a/map/first/last/min/max/take/drop) only understood
Integer and String begins; a Symbol, Date, or any object with #succ and #<=>
raised "can't iterate from …". A new vm.rangeElemsV materialises a bounded range
generically: Integer/String keep the fast path, a Symbol walks like a String
range and re-symbolises, and any other #succ-responder is walked by #succ while
#<=> has not passed end (iteration stops if #<=> stops ordering the value, as
MRI does). Range#each also gains the endless Symbol/#succ form. Materialising an
endless range still raises, and a begin without #succ is a TypeError.

This exposed a pre-existing bug in strRangeElems: a single-byte..single-byte
String range was walked by #succ, so "A".."z" stopped at "Z" (Z#succ is "AA")
instead of crossing the punctuation to "z". MRI iterates such a range by byte
value, so it now yields all 58 elements; multi-character ranges keep the
#succ-with-length-guard walk. This fixes String ranges and Symbol ranges alike.

Verified against ruby 4.0.6. Full package coverage stays at 100.0%. Zero-
regression rubyspec sweep; core/range/each_spec 7 -> 8, core/range/to_a_spec
5 -> 6, and Symbol/String single-byte ranges are now MRI-correct.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@tannevaled
tannevaled merged commit 67b7de3 into main Aug 26, 2026
7 checks passed
@tannevaled
tannevaled deleted the feat/cluster31 branch August 26, 2026 09:06
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.

1 participant