Skip to content

Commit

Permalink
Handle the case of **nil in post parameters
Browse files Browse the repository at this point in the history
Historically, the Sorbet legacy parser has declared bankruptcy in this case
and replaced the entire tree with a `Nil` node. Prism actually handles this
case, which is definitely a better/more complete approach, so I propose
to leave it like this for now and revisit as we're doing more error handling.
  • Loading branch information
egiurleo committed Dec 19, 2024
1 parent 2ce2215 commit 311b002
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion parser/prism/Translator.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1033,7 +1033,19 @@ unique_ptr<parser::Node> Translator::translate(pm_node_t *node) {
if (paramsNode->rest != nullptr)
params.emplace_back(translate(paramsNode->rest));

translateMultiInto(params, posts);
// Note: This is actually a divergence from the legacy Sorbet parser behavior, which doesn't handle `**nil`
// as a post argument. In this case, the legacy parser would just replace the entire tree with `Nil`.
for (auto &post : posts) {
switch (PM_NODE_TYPE(post)) {
case PM_NO_KEYWORDS_PARAMETER_NODE: { // `**nil`
params.emplace_back(translateSimpleKeyword<parser::Kwnilarg>(post));
break;
}
default:
params.emplace_back(translate(post));
}
}

translateMultiInto(params, keywords);

if (auto prismKwRestNode = paramsNode->keyword_rest; prismKwRestNode != nullptr) {
Expand Down

0 comments on commit 311b002

Please sign in to comment.