Skip to content

Add Enumerator::ArithmeticSequence and MRI-exact Numeric#step arg errors - #515

Merged
tannevaled merged 1 commit into
mainfrom
feat/agent-numeric
Aug 30, 2026
Merged

tannevaled merged 1 commit into
mainfrom
feat/agent-numeric

Conversation

@tannevaled

Copy link
Copy Markdown
Contributor

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), the to:/by: keyword form) now returns an Enumerator::ArithmeticSequence instead of a bare Enumerator. The constant did not exist, so every describe block that referenced it at load time raised uninitialized constant Enumerator::ArithmeticSequence and lost all its examples to a NameError — hence the large pass jump once the class exists.

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 with a RangeError, as MRI does). A String step still yields a plain Enumerator whose #size raises only when asked.

Argument validation (Integer/Float #step only; Range untouched)

  • String step → ArgumentError: comparison of String with 0 failed (was step can't be String); a Symbol step quotes its class the same way.
  • nil step → TypeError: step must be numeric.
  • Both the block form and the no-block #size raise. Every message verified byte-for-byte against MRI.

Range#step keeps its own inherited message, so the shared walkers stay at baseline behaviour and core/range/step_spec does 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 &block parameter does not capture the block passed to #call (Proc#call discards 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's exec to bind the &block param separately from the yield block (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 -l empty on changed files.
  • Merged coverage (-coverpkg across ./internal/..., run over ./...) = 100.0%; every added/changed function at 100.0%.
  • New tests in internal/vm/numeric_step_conformance_test.go, each expectation MRI-verified.

🤖 Generated with Claude Code

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>
@tannevaled
tannevaled merged commit b200cf7 into main Aug 30, 2026
7 checks passed
@tannevaled
tannevaled deleted the feat/agent-numeric branch August 30, 2026 22:04
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