Allow escaping from ensures through next

Fixes [Bug #21001]
This commit is contained in:
Kevin Newton 2025-01-05 20:42:09 -05:00
parent a61c16ba42
commit 31905d9e23
Notes: git 2025-01-06 18:18:44 +00:00
2 changed files with 21 additions and 9 deletions

View File

@ -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;

View File

@ -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