Skip to content

Commit

Permalink
Merge pull request #314 from Shopify/emily/lambda-no-params
Browse files Browse the repository at this point in the history
Fix edge case for lambda with no params
  • Loading branch information
egiurleo authored Oct 30, 2024
2 parents 0cd6d8f + 82a54ad commit 57bba3a
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 0 deletions.
4 changes: 4 additions & 0 deletions parser/prism/Translator.cc
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,10 @@ unique_ptr<parser::Node> Translator::translate(pm_node_t *node) {
case PM_BLOCK_PARAMETERS_NODE: { // The parameters declared at the top of a PM_BLOCK_NODE
auto paramsNode = down_cast<pm_block_parameters_node>(node);

if (paramsNode->parameters == nullptr) {
return make_unique<parser::Args>(location, NodeVec{});
}

// Sorbet's legacy parser inserts locals (Shadowargs) into the block's Args node, along with its other
// parameters. So we need to extract the args vector from the Args node, and insert the locals at the end of
// it.
Expand Down
26 changes: 26 additions & 0 deletions test/prism_regression/lambda.parse-tree.exp
Original file line number Diff line number Diff line change
Expand Up @@ -192,5 +192,31 @@ Begin {
}
}
}
Block {
send = Send {
receiver = Const {
scope = NULL
name = <C <U Kernel>>
}
method = <U lambda>
args = [
]
}
args = Args {
args = [
]
}
body = Send {
receiver = Integer {
val = "1"
}
method = <U +>
args = [
Integer {
val = "2"
}
]
}
}
]
}
3 changes: 3 additions & 0 deletions test/prism_regression/lambda.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,6 @@ def method_returning_lambda
-> { 123 }
end
end

# Empty lambda parameters
->() { 1 + 2 }

0 comments on commit 57bba3a

Please sign in to comment.