diff options
| author | Peter Zhu <peter@peterzhu.ca> | 2024-01-16 10:30:31 -0500 |
|---|---|---|
| committer | Peter Zhu <peter@peterzhu.ca> | 2024-01-16 12:55:57 -0500 |
| commit | 07b9b53459d1842e7066b248d48ef4952c6868d3 (patch) | |
| tree | 6bec9e8a5244c4b80dfb886fbb145803ff91ca8a | |
| parent | 7bd7030a96cdc106e347e0d48cfacfb80fb0f8db (diff) | |
[PRISM] Fix crash with empty ensure blocks
Fixes ruby/prism#2179.
| -rw-r--r-- | prism_compile.c | 4 | ||||
| -rw-r--r-- | test/ruby/test_compile_prism.rb | 16 |
2 files changed, 19 insertions, 1 deletions
diff --git a/prism_compile.c b/prism_compile.c index 88362fa7ac..722dabf8ab 100644 --- a/prism_compile.c +++ b/prism_compile.c @@ -3247,14 +3247,16 @@ pm_compile_node(rb_iseq_t *iseq, const pm_node_t *node, LINK_ANCHOR *const ret, PM_PUTNIL_UNLESS_POPPED; } } + ADD_LABEL(ret, eend); + ADD_LABEL(ret, econt); + if (!popped) { PM_NOP; } pm_statements_node_t *statements = begin_node->ensure_clause->statements; if (statements) { PM_COMPILE((pm_node_t *)statements); - ADD_LABEL(ret, econt); PM_POP_UNLESS_POPPED; } diff --git a/test/ruby/test_compile_prism.rb b/test/ruby/test_compile_prism.rb index cd521e6766..bc9f0b3aba 100644 --- a/test/ruby/test_compile_prism.rb +++ b/test/ruby/test_compile_prism.rb @@ -962,6 +962,22 @@ module Prism end prism_test_ensure_node CODE + + # Test empty ensure block + assert_prism_eval(<<~RUBY) + res = [] + + begin + begin + raise + ensure + end + rescue + res << "rescue" + end + + res + RUBY end def test_NextNode |
