summaryrefslogtreecommitdiff
path: root/test/ruby
diff options
context:
space:
mode:
authorAaron Patterson <tenderlove@ruby-lang.org>2024-01-22 11:24:34 -0800
committerAaron Patterson <aaron.patterson@gmail.com>2024-01-22 12:02:03 -0800
commit7db683222528ca4850fed57529679e5aa14b0a88 (patch)
tree6e2b554e993347054cc6021c9ad51caf3df94643 /test/ruby
parent1236cad92d509c299f0199c69ed752ea92f21023 (diff)
Fix compiling rescue + ensure
When we're compiling begin / rescue / ensure nodes, we need to "wrap" the code in the begin statements correctly. The wrapping is like this: (ensure code (rescue code (begin code))) This patch pulls the each leg in to its own function, then calls the appropriate wrapping function depending on whether there are ensure / rescue legs. Fixes: https://github.com/ruby/prism/issues/2221
Diffstat (limited to 'test/ruby')
-rw-r--r--test/ruby/test_compile_prism.rb16
1 files changed, 16 insertions, 0 deletions
diff --git a/test/ruby/test_compile_prism.rb b/test/ruby/test_compile_prism.rb
index 8f42fb5851..29f0530462 100644
--- a/test/ruby/test_compile_prism.rb
+++ b/test/ruby/test_compile_prism.rb
@@ -1506,6 +1506,22 @@ a
CODE
end
+ def test_rescue_with_ensure
+ assert_prism_eval(<<-CODE)
+begin
+ begin
+ raise "a"
+ rescue
+ raise "b"
+ ensure
+ raise "c"
+ end
+rescue => e
+ e.message
+end
+ CODE
+ end
+
def test_required_kwarg_ordering
assert_prism_eval("def self.foo(a: 1, b:); [a, b]; end; foo(b: 2)")
end