Skip to content

Support forwarded arguments in calls, super, and nested blocks#416

Merged
mame merged 3 commits intoruby:masterfrom
pvcresin:fix_forwarding_arguments
Apr 7, 2026
Merged

Support forwarded arguments in calls, super, and nested blocks#416
mame merged 3 commits intoruby:masterfrom
pvcresin:fix_forwarding_arguments

Conversation

@pvcresin
Copy link
Copy Markdown
Contributor

@pvcresin pvcresin commented Apr 3, 2026

Known issue: forwarding-arguments

Summary

  • support argument forwarding with ... in direct calls, super(...), and nested blocks
  • move the forwarding-arguments case from known issues to regular scenarios
  • add scenario coverage for bar(...), super(...), and 1.times { bar(...) }

Design

  • model ... as forwarded actual arguments instead of reconstructing it from local variables
  • keep the forwarding state in a dedicated object referenced from LocalEnv
  • reuse the same forwarding state for super(...) and nested block bodies

Note

The implementation is based on the existing argument-binding logic in MethodDefBox#pass_arguments.

ForwardingArguments#accept_actual_arguments mirrors that flow to capture the actual arguments received by def foo(...), and ForwardingArguments#to_actual_arguments converts that captured state back into ActualArguments for direct calls, super(...), and nested block calls.

@pvcresin pvcresin changed the title Support direct argument forwarding Support forwarded arguments in calls, super, and nested blocks Apr 3, 2026
@mame
Copy link
Copy Markdown
Member

mame commented Apr 7, 2026

Thanks @pvcresin! Clean design and the test coverage for the three cases is convincing.

Does bar(extra, ...) work? In CallBaseNode#install0, when @forwarding_arguments is true, @positional_args looks discarded entirely. Probably out of scope for this PR. Could you drop it into scenario/known-issues/ so we don't lose track?

pvcresin and others added 3 commits April 7, 2026 17:04
Co-authored-by: OpenAI Codex <codex@openai.com>
Co-authored-by: OpenAI Codex <codex@openai.com>
Co-authored-by: OpenAI Codex <codex@openai.com>
@pvcresin pvcresin force-pushed the fix_forwarding_arguments branch from 56012e8 to a826825 Compare April 7, 2026 08:06
@pvcresin
Copy link
Copy Markdown
Contributor Author

pvcresin commented Apr 7, 2026

@mame Good catch, and you're right: bar(extra, ...) does not work on this branch because the leading positional args are dropped when @forwarding_arguments is true.

I've added a regression scenario under scenario/known-issues/ so we don't lose track of it:
scenario/known-issues/forwarding-arguments-extra-positional.rb

I also rebased the branch onto the latest master.

@mame mame merged commit a7177ac into ruby:master Apr 7, 2026
6 checks passed
@mame
Copy link
Copy Markdown
Member

mame commented Apr 7, 2026

Thanks!

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.

2 participants