Skip to content

Bind a proc's &b block parameter to the block passed to Proc#call - #519

Merged
tannevaled merged 1 commit into
mainfrom
feat/proc-call-block-arg
Aug 31, 2026
Merged

tannevaled merged 1 commit into
mainfrom
feat/proc-call-block-arg

Conversation

@tannevaled

Copy link
Copy Markdown
Contributor

A proc/lambda with its own &b block parameter did not capture the block handed to Proc#call / #[] / #() — procCall discarded it — so &b was always nil and any ->(&b){ … b.call } or block-forwarding lambda (->(r,*a,&b){ r.step(*a,&b) }) failed with a NoMethodError.

exec now takes a separate blockArg for the &b slot: for a method it equals the block (a method's block backs both &b and a bare yield), but for Proc#call the block passed to .call binds &b while yield inside the proc still reaches the block captured where the proc was defined — the two diverge, matching MRI (proc { yield } called with a different block still yields to the captured one).

Exposing the working block-form of Numeric#step surfaced a pre-existing non-termination: a non-finite start (Float::INFINITY.step(Float::INFINITY, 1)) made every term the same Infinity, looping forever. MRI's step count (stop-start)/step is NaN/negative there, so it yields nothing — guarded.

Conformance: core/numeric/step_spec 184 → 208 (fail 24 → 0); core/proc/call_spec 13 → 15; no regressions across a block-heavy sweep. FLOOR 17270 → 17300 (measured total 17342). go test ./... green, native + wasip1/wasm build, gofmt clean, 100% merged coverage of the new code.

🤖 Generated with Claude Code

A proc/lambda with its own `&b` block parameter did not capture the block
handed to Proc#call / #[] / #() — procCall discarded it — so `&b` was
always nil and any `->(&b){ … b.call }` or block-forwarding lambda
(`->(r,*a,&b){ r.step(*a,&b) }`) failed with a NoMethodError. exec now
takes a separate blockArg for the `&b` slot: for a method it equals the
block (a method's block backs both `&b` and a bare `yield`), but for
Proc#call the block passed to `.call` binds `&b` while `yield` inside the
proc still reaches the block captured where the proc was defined — the two
diverge, matching MRI.

Exposing the working block-form of Numeric#step surfaced a pre-existing
non-termination: a non-finite start (Float::INFINITY.step(Float::INFINITY,
1)) made every term the same Infinity, looping forever. MRI's step count
(stop-start)/step is NaN/negative there, so it yields nothing; guard it.

core/numeric/step_spec 184 -> 208 (fail 24 -> 0); core/proc/call_spec
13 -> 15. ruby/spec ratchet FLOOR 17270 -> 17300 (measured total 17342).

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@tannevaled
tannevaled merged commit 259785b into main Aug 31, 2026
7 checks passed
@tannevaled
tannevaled deleted the feat/proc-call-block-arg branch August 31, 2026 09:59
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