Skip to content

Commit

Permalink
Merge pull request #1791 from makenowjust/fix-1772
Browse files Browse the repository at this point in the history
Reset do_loop_stack around a body of a endless method definition
  • Loading branch information
kddnewton authored Nov 9, 2023
2 parents add546d + cdf58e8 commit 4414ee0
Show file tree
Hide file tree
Showing 3 changed files with 83 additions and 42 deletions.
2 changes: 2 additions & 0 deletions src/prism.c
Original file line number Diff line number Diff line change
Expand Up @@ -14326,6 +14326,7 @@ parse_expression_prefix(pm_parser_t *parser, pm_binding_power_t binding_power) {
equal = parser->previous;

context_push(parser, PM_CONTEXT_DEF);
pm_do_loop_stack_push(parser, false);
statements = (pm_node_t *) pm_statements_node_create(parser);

pm_node_t *statement = parse_expression(parser, PM_BINDING_POWER_DEFINED + 1, PM_ERR_DEF_ENDLESS);
Expand All @@ -14338,6 +14339,7 @@ parse_expression_prefix(pm_parser_t *parser, pm_binding_power_t binding_power) {
}

pm_statements_node_body_append((pm_statements_node_t *) statements, statement);
pm_do_loop_stack_pop(parser);
context_pop(parser);
end_keyword = not_provided(parser);
} else {
Expand Down
2 changes: 2 additions & 0 deletions test/prism/fixtures/while.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,5 @@ while class Foo a = tap do end; end; break; end
while class << self; tap do end; end; break; end

while class << self; a = tap do end; end; break; end

while def foo = bar do end; end
121 changes: 79 additions & 42 deletions test/prism/snapshots/while.txt

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

0 comments on commit 4414ee0

Please sign in to comment.