Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix edge case for lambda with no params #314

Merged
merged 1 commit into from
Oct 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 }
Copy link

@amomchilov amomchilov Oct 30, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Interesting that there's a difference between ->() {} and -> {}

Loading