From 7db683222528ca4850fed57529679e5aa14b0a88 Mon Sep 17 00:00:00 2001 From: Aaron Patterson Date: Mon, 22 Jan 2024 11:24:34 -0800 Subject: 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 --- test/ruby/test_compile_prism.rb | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'test/ruby') 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 -- cgit v1.2.3