Skip to content

Commit

Permalink
Merge pull request #2425 from haldun/haldun/fix-rescue-with-calls
Browse files Browse the repository at this point in the history
  • Loading branch information
kddnewton authored Feb 15, 2024
2 parents 0adb234 + b7407ae commit 4d610e0
Show file tree
Hide file tree
Showing 3 changed files with 112 additions and 43 deletions.
13 changes: 12 additions & 1 deletion src/prism.c
Original file line number Diff line number Diff line change
Expand Up @@ -16769,7 +16769,18 @@ parse_assignment_values(pm_parser_t *parser, pm_binding_power_t previous_binding
if (is_single_value && match1(parser, PM_TOKEN_KEYWORD_RESCUE_MODIFIER)) {
pm_token_t rescue = parser->current;
parser_lex(parser);
pm_node_t *right = parse_expression(parser, binding_power, false, PM_ERR_RESCUE_MODIFIER_VALUE);

bool accepts_command_call_inner = false;

// RHS can accept command call iff the value is a call with arguments but without paranthesis.
if (PM_NODE_TYPE_P(value, PM_CALL_NODE)) {
pm_call_node_t *call_node = (pm_call_node_t *)value;
if ((call_node->arguments != NULL) && (call_node->opening_loc.start == NULL)) {
accepts_command_call_inner = true;
}
}

pm_node_t *right = parse_expression(parser, binding_power, accepts_command_call_inner, PM_ERR_RESCUE_MODIFIER_VALUE);

return (pm_node_t *) pm_rescue_modifier_node_create(parser, value, &rescue, right);
}
Expand Down
2 changes: 2 additions & 0 deletions test/prism/fixtures/rescue.txt
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,5 @@ rescue
end

foo if bar rescue baz

z = x y rescue c d
140 changes: 98 additions & 42 deletions test/prism/snapshots/rescue.txt

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 4d610e0

Please sign in to comment.