Skip to content

Commit

Permalink
Avoid translating implicit rest nodes in parameters
Browse files Browse the repository at this point in the history
  • Loading branch information
st0012 committed Feb 12, 2025
1 parent a06ff97 commit 5db265d
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 2 deletions.
7 changes: 5 additions & 2 deletions parser/prism/Translator.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1037,8 +1037,11 @@ unique_ptr<parser::Node> Translator::translate(pm_node_t *node) {
translateMultiInto(params, requireds);
translateMultiInto(params, optionals);

if (paramsNode->rest != nullptr)
params.emplace_back(translate(paramsNode->rest));
auto prismRestNode = paramsNode->rest;
// Implicit rest node in parameters don't need to be translated
if (prismRestNode != nullptr && !PM_NODE_TYPE_P(prismRestNode, PM_IMPLICIT_REST_NODE)) {
params.emplace_back(translate(prismRestNode));
}

translateMultiInto(params, posts);
translateMultiInto(params, keywords);
Expand Down
19 changes: 19 additions & 0 deletions test/prism_regression/call_block_param.parse-tree.exp
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,25 @@ Begin {
}
body = NULL
}
Block {
send = Send {
receiver = NULL
method = <U foo>
args = [
]
}
args = Args {
args = [
Arg {
name = <U bar>
}
Arg {
name = <U baz>
}
]
}
body = NULL
}
Send {
receiver = NULL
method = <U foo>
Expand Down
2 changes: 2 additions & 0 deletions test/prism_regression/call_block_param.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@

foo { |bar; baz, qux| }

foo { |bar, baz,| }

foo(&forwarded_block)

foo&.bar {}
Expand Down

0 comments on commit 5db265d

Please sign in to comment.