Handle forwarding parameters in parser - #578
Open
Morriar wants to merge 1 commit into
Open
Conversation
Expand `...` (ForwardingParameterNode) into `*args, **kwargs, &block` instead of crashing with an unexpected parameter error. Based on #562
Member
|
I think the changes are fine, but I do want to confirm one aspect of this. There one minor difference before def foo(...)
# there's no way to use forwarding parameters that isn't including all
# of them. I can't print only the keyword ones or refer exclusively to the block
end
def bar(*args, **kwargs, &block)
# Here, while equivalent at the call site (accepts any argument), I can refer
# to the individual parameter parts
endIs this something we need to be concerned about? Would it be better to have RBI print the forwarding parameter instead? |
amomchilov
approved these changes
Apr 6, 2026
Morriar
added a commit
that referenced
this pull request
Jul 17, 2026
Ruby argument forwarding (...) is a distinct parameter form, and expanding it to *args, **kwargs, &block loses source fidelity. Model it explicitly so RBI parsing and printing round-trip forwarding methods. Add RBI::ForwardingParam and wire it through parser, visitors, printers, and RBS output. Skip add-sig templates for forwarding methods because Sorbet doesn't support signatures on argument forwarding. Treat forwarding params as merge-compatible only with the same forwarding shape. Closes #562. Closes #578. Signed-off-by: Alexandre Terrasa <alexandre.terrasa@shopify.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
Expand
...(ForwardingParameterNode) into*args, **kwargs, &blockinstead of crashing with an unexpected parameter error.Based on #562 by @kddnewton — simplified the approach to avoid wrapping every case in arrays: just
map→flat_mapand a single newwhenbranch.Includes test for both
def m1(...)anddef m2(a, ...).Closes #562