From 31905d9e23ec6d1fa2a52f1ef2533f2056e7c9fb Mon Sep 17 00:00:00 2001 From: Kevin Newton Date: Sun, 5 Jan 2025 20:42:09 -0500 Subject: [PATCH] Allow escaping from ensures through next Fixes [Bug #21001] --- prism_compile.c | 9 --------- test/ruby/test_compile_prism.rb | 21 +++++++++++++++++++++ 2 files changed, 21 insertions(+), 9 deletions(-) diff --git a/prism_compile.c b/prism_compile.c index db8e9cb3b2..a47e669d72 100644 --- a/prism_compile.c +++ b/prism_compile.c @@ -8720,16 +8720,7 @@ pm_compile_node(rb_iseq_t *iseq, const pm_node_t *node, LINK_ANCHOR *const ret, const pm_ensure_node_t *cast = (const pm_ensure_node_t *) node; if (cast->statements != NULL) { - LABEL *start = NEW_LABEL(location.line); - LABEL *end = NEW_LABEL(location.line); - PUSH_LABEL(ret, start); - - LABEL *prev_end_label = ISEQ_COMPILE_DATA(iseq)->end_label; - ISEQ_COMPILE_DATA(iseq)->end_label = end; - PM_COMPILE((const pm_node_t *) cast->statements); - ISEQ_COMPILE_DATA(iseq)->end_label = prev_end_label; - PUSH_LABEL(ret, end); } return; diff --git a/test/ruby/test_compile_prism.rb b/test/ruby/test_compile_prism.rb index 4a18040d63..9135495d1d 100644 --- a/test/ruby/test_compile_prism.rb +++ b/test/ruby/test_compile_prism.rb @@ -1192,6 +1192,27 @@ a res RUBY + + # Bug #21001 + assert_prism_eval(<<~RUBY) + RUN_ARRAY = [1,2] + + MAP_PROC = Proc.new do |&blk| + block_results = [] + RUN_ARRAY.each do |value| + block_value = blk.call(value) + block_results.push block_value + end + block_results + ensure + next block_results + end + + MAP_PROC.call do |value| + break if value > 1 + next value + end + RUBY end def test_NextNode