Skip to content

Commit 31905d9

Browse files
committed
Allow escaping from ensures through next
Fixes [Bug #21001]
1 parent a61c16b commit 31905d9

File tree

2 files changed

+21
-9
lines changed

2 files changed

+21
-9
lines changed

prism_compile.c

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8720,16 +8720,7 @@ pm_compile_node(rb_iseq_t *iseq, const pm_node_t *node, LINK_ANCHOR *const ret,
87208720
const pm_ensure_node_t *cast = (const pm_ensure_node_t *) node;
87218721

87228722
if (cast->statements != NULL) {
8723-
LABEL *start = NEW_LABEL(location.line);
8724-
LABEL *end = NEW_LABEL(location.line);
8725-
PUSH_LABEL(ret, start);
8726-
8727-
LABEL *prev_end_label = ISEQ_COMPILE_DATA(iseq)->end_label;
8728-
ISEQ_COMPILE_DATA(iseq)->end_label = end;
8729-
87308723
PM_COMPILE((const pm_node_t *) cast->statements);
8731-
ISEQ_COMPILE_DATA(iseq)->end_label = prev_end_label;
8732-
PUSH_LABEL(ret, end);
87338724
}
87348725

87358726
return;

test/ruby/test_compile_prism.rb

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1192,6 +1192,27 @@ def self.prism_test_ensure_node
11921192
11931193
res
11941194
RUBY
1195+
1196+
# Bug #21001
1197+
assert_prism_eval(<<~RUBY)
1198+
RUN_ARRAY = [1,2]
1199+
1200+
MAP_PROC = Proc.new do |&blk|
1201+
block_results = []
1202+
RUN_ARRAY.each do |value|
1203+
block_value = blk.call(value)
1204+
block_results.push block_value
1205+
end
1206+
block_results
1207+
ensure
1208+
next block_results
1209+
end
1210+
1211+
MAP_PROC.call do |value|
1212+
break if value > 1
1213+
next value
1214+
end
1215+
RUBY
11951216
end
11961217

11971218
def test_NextNode

0 commit comments

Comments
 (0)