Repository navigation
Range + Comparable: advance MRI 4.0.6 conformance - #539
Merged
Merged
Conversation
Range#== / #eql? / #hash now compare by endpoint value (dispatching #== /#eql? and mixing the two bounds + exclude_end? into the hash) rather than by object identity, so custom Comparable endpoints, Range subclasses and endless ranges compare and hash like MRI. Range#inspect renders (nil..nil) as "nil..nil" while keeping (1..) and (..1) unchanged, matching MRI's range_inspect rule (to_s is unchanged). Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
…mpint ==
- Range#initialize: private native initializer behind Range.new — arity 2..3,
comparable-endpoints check, FrozenError on an already-constructed (frozen)
Range, fills a Range.allocate'd instance.
- Range#count returns Float::INFINITY for any unbounded range (nil begin or
end), even a String/Float bound whose #size is nil.
- Range#step: a non-Integer step over a String range advances by #+ (MRI 4.0),
e.g. ("A".."AAA").step("A") => "A","AA","AAA"; an incompatible step
raises TypeError via String#+.
- Range#entries is now a true alias of #to_a (shared method object).
- rangeElemsV names the offending endpoint's class ("can't iterate from
NilClass") rather than its value, matching MRI (fixes Range#to_set message).
- Comparable#== follows rb_cmpint: nil is unequal, a zero (incl. 0.0) result is
equal, and a non-nil non-comparison result (a String) raises ArgumentError.
Adds internal/vm/range_comparable_residuals_test.go.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
- Range#reverse_each: supports beginless Integer ranges (descends from the end forever; bounded via take), Symbol and generic #succ ranges (via rangeElemsV), and its Enumerator #size names the END's class for a non-countable begin, returns Infinity for a beginless Integer end (MRI 4.0). - Range#step without a block returns an Enumerator::ArithmeticSequence for a numeric range (Numeric begin, or beginless with Numeric end) and a plain Enumerator for a String range, matching MRI 2.6+. - Range#% is Range#step's alias, producing an ArithmeticSequence whose #inspect reads ((1..10).%(2)); the % operator on a Range now dispatches the method. - Enumerator::ArithmeticSequence#inspect/#to_s follow MRI: ((b..e).step(s)) / ((b..e).%(s)) for a Range receiver, (b.step(e, s)) for a Numeric receiver. - Updated range_edges_test.go and step_test.go, which encoded pre-4.0 behavior (beginless reverse_each raising; blockless numeric step returning a plain Enumerator), to the MRI 4.0.6 results. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
…rd case
The String-only #+ walk always compares two Strings, so rangeCmpV never
reports incomparability; drop the dead guard and add a backward-range test
(( 'D'..'A' ).step('A') => []) covering the overshoot return. Keeps the
changed function at 100% coverage.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
tannevaled
added a commit
that referenced
this pull request
Sep 1, 2026
Locks in #535 (String methods: index/casecmp/chomp/gsub/scan/tr/... ~+110), #536 (IO/StringIO reader+writer), #538 (Array#[]= auto-grow + mutators), #539 (Range + Comparable), #540 (Struct + Data), #541 (Time). Measured 17983 passing on the pinned corpus, up from 17654. 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.
Advances MRI 4.0.6 conformance of the Range + Comparable clusters
(core/range/, core/comparable/). Measured against ruby/spec and verified
byte-for-byte against MRI 4.0.6.
Range
==/eql?/hash: compare by endpoint value (dispatching#==/#eql?and mixing both bounds +exclude_end?into the hash) rather than byobject identity, so custom Comparable endpoints, Range subclasses and endless
ranges compare/hash like MRI (via message send).
#inspect:(nil..nil).inspectis now"nil..nil"(MRI's range_inspectrule); one-sided unbounded forms and
#to_sare unchanged.#initialize: added the private native initializer behindRange.new—arity 2..3, comparable-endpoints check,
FrozenErroron an already-constructedRange, fills a
Range.allocate'd instance.#count: returnsFloat::INFINITYfor any unbounded range.#step: a non-Integer step over a String range advances by#+(MRI 4.0),e.g.
("A".."AAA").step("A"); without a block a numeric range returns anEnumerator::ArithmeticSequence(String range stays a plainEnumerator).#%: Range#step's alias, producing an ArithmeticSequence whose#inspectreads
((1..10).%(2)); the%operator on a Range now dispatches the method.Enumerator::ArithmeticSequence#inspect/#to_s: MRI format(
((b..e).step(s))/((b..e).%(s)),(b.step(e, s))).#reverse_each: supports beginless Integer ranges (descend from the end,bounded via
take), Symbol and generic#succranges; its Enumerator#sizenames the end's class and is
Infinityfor a beginless Integer end.#entriesis now a true alias of#to_a;rangeElemsVnames theoffending endpoint's class (fixes Range#to_set's message).
Comparable
#==followsrb_cmpint:nilis unequal, a zero (incl.0.0) result isequal, and a non-nil non-comparison result (a String) raises
ArgumentError.Spec deltas (core/range + core/comparable)
~28 more examples pass. Remaining failures are almost entirely blocked by an
mspec mock
.with()argument-matching bug (out of the Range/Comparable scope):x <=> yreturns the wrong stubbed value, which sinks the mock-driven each /minmax / reverse_each / step cases. One bsearch case depends on repeated
evalin a single example (eval-cache infra), and one step case needs the
#coercestep protocol.
Gates
go test ./internal/vm/green;go test ./...greentool cover -func | tail -1= 100.0%GOOS=wasip1 GOARCH=wasm go build ./...OK;gofmt -lcleanAdds
internal/vm/range_comparable_residuals_test.go; updatesrange_edges_test.goandstep_test.gofrom pre-4.0 to MRI 4.0.6 expectations.🤖 Generated with Claude Code