From 82a54ad0ffd37995dbfa9198f5e81ce11d46d217 Mon Sep 17 00:00:00 2001 From: Emily Samp Date: Wed, 30 Oct 2024 12:02:45 -0500 Subject: [PATCH] Fix edge case for lambda with no params --- parser/prism/Translator.cc | 4 ++++ test/prism_regression/lambda.parse-tree.exp | 26 +++++++++++++++++++++ test/prism_regression/lambda.rb | 3 +++ 3 files changed, 33 insertions(+) diff --git a/parser/prism/Translator.cc b/parser/prism/Translator.cc index aa198ae5ce9..f2d3f675eb7 100644 --- a/parser/prism/Translator.cc +++ b/parser/prism/Translator.cc @@ -245,6 +245,10 @@ unique_ptr 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(node); + if (paramsNode->parameters == nullptr) { + return make_unique(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. diff --git a/test/prism_regression/lambda.parse-tree.exp b/test/prism_regression/lambda.parse-tree.exp index 00115df8ac5..43cdb33a072 100644 --- a/test/prism_regression/lambda.parse-tree.exp +++ b/test/prism_regression/lambda.parse-tree.exp @@ -192,5 +192,31 @@ Begin { } } } + Block { + send = Send { + receiver = Const { + scope = NULL + name = > + } + method = + args = [ + ] + } + args = Args { + args = [ + ] + } + body = Send { + receiver = Integer { + val = "1" + } + method = + args = [ + Integer { + val = "2" + } + ] + } + } ] } diff --git a/test/prism_regression/lambda.rb b/test/prism_regression/lambda.rb index c3f78193f25..a99791717cc 100644 --- a/test/prism_regression/lambda.rb +++ b/test/prism_regression/lambda.rb @@ -19,3 +19,6 @@ def method_returning_lambda -> { 123 } end end + +# Empty lambda parameters +->() { 1 + 2 }