Repository navigation
Add Enumerator::ArithmeticSequence and MRI-exact Numeric#step arg errors - #515
Merged
Merged
Conversation
Numeric#step / Integer#step / Float#step now match MRI 4.0.x for the no-block form and for argument validation, advancing core/numeric/step_spec from pass=119 (fail=24 error=4) to pass=184 (fail=24 error=0). Enumerator::ArithmeticSequence The no-block form (1.step(10, 2), 1.step, 1.0.step(2.0, 0.5), the to:/by: keyword form) now returns an Enumerator::ArithmeticSequence instead of a bare Enumerator. The class was missing, so every describe block that named it at load time raised "uninitialized constant Enumerator::ArithmeticSequence" and lost all its examples to a NameError. It is a step-driven, size-bearing Enumerator (its #each/#to_a/#first/#size reuse the existing step machinery) that additionally answers #begin/#end/#step/#exclude_end? and #last (#last refuses an endless sequence, as MRI does). A String step still yields a plain Enumerator whose #size raises only when asked. Argument validation (Integer#step / Float#step only, not Range#step) A String step now raises ArgumentError "comparison of String with 0 failed" (was "step can't be String"); a Symbol step quotes its class the same way; a nil step raises TypeError "step must be numeric". The block form and the no-block form's #size both raise. Range#step keeps its own inherited message, so the shared walkers are untouched and core/range/step_spec is unchanged (its pass set is identical before and after). The remaining 24 failures are a separate, pre-existing root cause outside the step code: a lambda/proc declared with a &block parameter does not capture the block passed to #call (Proc#call discards it), so the spec's argument-style lambda forwards a nil block. Fixing it needs the VM's exec to bind the &block param separately from the yield block, a change beyond this cluster. Tests: internal/vm/numeric_step_conformance_test.go, every expectation verified against MRI. Merged coverage stays 100.0%. 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.
Summary
Advances MRI 4.0.x conformance of
Numeric#step/Integer#step/Float#step.core/numeric/step_spec.rb: pass 119 → 184 (+65), errors 4 → 0 (fail unchanged at 24 — see below).core/range/step_spec.rb: unchanged (pass 66; its exact pass set is identical before/after — verified by diffing the non-passing example sets).What changed
Enumerator::ArithmeticSequence(was entirely missing)The no-block form (
1.step(10, 2),1.step,1.0.step(2.0, 0.5), theto:/by:keyword form) now returns anEnumerator::ArithmeticSequenceinstead of a bareEnumerator. The constant did not exist, so everydescribeblock that referenced it at load time raiseduninitialized constant Enumerator::ArithmeticSequenceand lost all its examples to aNameError— hence the large pass jump once the class exists.It is a step-driven, size-bearing
Enumerator(its#each/#to_a/#first/#sizereuse the existing step machinery) that additionally answers#begin/#end/#step/#exclude_end?and#last(#lastrefuses an endless sequence with aRangeError, as MRI does). A String step still yields a plainEnumeratorwhose#sizeraises only when asked.Argument validation (Integer/Float
#steponly; Range untouched)ArgumentError: comparison of String with 0 failed(wasstep can't be String); a Symbol step quotes its class the same way.TypeError: step must be numeric.#sizeraise. Every message verified byte-for-byte against MRI.Range#stepkeeps its own inherited message, so the shared walkers stay at baseline behaviour andcore/range/step_specdoes not regress.Remaining 24 failures — out of scope, separate root cause
All 24 (Infinity-yields-once ×6, String-step-raises ×12, does-not-rescue ×6) trace to one pre-existing bug outside the step code: a lambda/proc declared with a
&blockparameter does not capture the block passed to#call(Proc#calldiscards it), so the spec's argument-style lambda (-> r, *a, &b { r.step(*a, &b) }) forwards a nil block and the block-form behaviour never runs. Fixing it requires the VM'sexecto bind the&blockparam separately from theyieldblock (a hot-path signature change), which is beyond this cluster.Verification
go test ./...green;go test ./internal/vm/green.GOOS=wasip1 GOARCH=wasm go build ./...OK.gofmt -lempty on changed files.-coverpkgacross./internal/..., run over./...) = 100.0%; every added/changed function at 100.0%.internal/vm/numeric_step_conformance_test.go, each expectation MRI-verified.🤖 Generated with Claude Code