Repository navigation
Range: iterate Symbol/other #succ ranges, and fix single-byte String ranges - #461
Merged
Merged
Conversation
…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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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
#succand#<=>raisedcan't iterate from …. A newvm.rangeElemsVmaterialises a bounded range generically: Integer/String keep the fast path, a
Symbol walks like a String range and re-symbolises, and any other
#succ-responderis walked by
#succwhile#<=>has not passed end (iteration stops if#<=>stops ordering the value, as MRI does).
Range#eachalso gains the endlessSymbol/
#succform. Materialising an endless range still raises, and a beginwithout
#succis aTypeError.This exposed a pre-existing bug in
strRangeElems: a single-byte..single-byteString range was walked by
#succ, so"A".."z"stopped at"Z"("Z".succis"AA") instead of crossing the punctuation to"z". MRI iterates such a range bybyte 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_spec7 → 8,core/range/to_a_spec5 → 6, and Symbol/String single-byte ranges are nowMRI-correct.
🤖 Generated with Claude Code