summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJemma Issroff <[email protected]>2023-11-02 15:13:33 -0300
committerJemma Issroff <[email protected]>2023-11-02 17:46:43 -0300
commitc6f5c64639152b950d4d1ccbaa199b621099e2a5 (patch)
tree8b886834c55ee4d61c58c542a5c6b6ccca4fe69d
parent7f18448a8e086b79a806acae5dbdd967f321c783 (diff)
[PRISM] Fix popped for ForNode
-rw-r--r--prism_compile.c9
-rw-r--r--test/ruby/test_compile_prism.rb2
2 files changed, 4 insertions, 7 deletions
diff --git a/prism_compile.c b/prism_compile.c
index f4d69f2384..268055fae3 100644
--- a/prism_compile.c
+++ b/prism_compile.c
@@ -2236,7 +2236,8 @@ pm_compile_node(rb_iseq_t *iseq, const pm_node_t *node, LINK_ANCHOR *const ret,
ADD_LABEL(ret, retry_label);
- PM_COMPILE(for_node->collection);
+ PM_COMPILE_NOT_POPPED(for_node->collection);
+
child_iseq = NEW_CHILD_ISEQ(next_scope_node, make_name_for_block(iseq), ISEQ_TYPE_BLOCK, lineno);
ISEQ_COMPILE_DATA(iseq)->current_block = child_iseq;
ADD_SEND_WITH_BLOCK(ret, &dummy_line_node, idEach, INT2FIX(0), child_iseq);
@@ -2250,9 +2251,7 @@ pm_compile_node(rb_iseq_t *iseq, const pm_node_t *node, LINK_ANCHOR *const ret,
}
ELEM_INSERT_NEXT(&iobj->link, (LINK_ELEMENT*)retry_end_l);
- if (popped) {
- ADD_INSN(ret, &dummy_line_node, pop);
- }
+ PM_POP_IF_POPPED;
ISEQ_COMPILE_DATA(iseq)->current_block = prevblock;
ADD_CATCH_ENTRY(CATCH_TYPE_BREAK, retry_label, retry_end_l, child_iseq, retry_end_l);
@@ -3275,7 +3274,7 @@ pm_compile_node(rb_iseq_t *iseq, const pm_node_t *node, LINK_ANCHOR *const ret,
pm_for_node_t *for_node = (pm_for_node_t *)scope_node->ast_node;
ADD_GETLOCAL(ret, &dummy_line_node, 1, 0);
- pm_compile_node(iseq, for_node->index, ret, src, popped, scope_node);
+ PM_COMPILE(for_node->index);
ADD_INSN(ret, &dummy_line_node, nop);
}
default: {
diff --git a/test/ruby/test_compile_prism.rb b/test/ruby/test_compile_prism.rb
index b92f0a09d8..eb6a4f8b9a 100644
--- a/test/ruby/test_compile_prism.rb
+++ b/test/ruby/test_compile_prism.rb
@@ -540,11 +540,9 @@ module Prism
end
def test_ForNode
-=begin
assert_prism_eval("for i in [1,2] do; i; end")
assert_prism_eval("for @i in [1,2] do; @i; end")
assert_prism_eval("for $i in [1,2] do; $i; end")
-=end
# TODO: multiple assignment in ForNode index
#assert_prism_eval("for i, j in {a: 'b'} do; i; j; end")