From a3a74771f23b4e31c1aaa33e2ffb5ba4a1f51ffe Mon Sep 17 00:00:00 2001 From: Nobuyoshi Nakada Date: Wed, 19 Jul 2023 12:42:20 +0900 Subject: [PATCH] Add a corner case for `return` --- test/ruby/test_syntax.rb | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/test/ruby/test_syntax.rb b/test/ruby/test_syntax.rb index 670bb27892..5b5666be10 100644 --- a/test/ruby/test_syntax.rb +++ b/test/ruby/test_syntax.rb @@ -1412,6 +1412,16 @@ eom assert_normal_exit('END {return}') end + def test_return_in_BEGIN_in_eval + # `BEGIN` in `eval` is allowed, even inside a method, and `return` + # from that block exits from that method without `LocalJumpError`. + obj = Object.new + def obj.ok + eval("BEGIN {return :ok}") + end + assert_equal :ok, assert_nothing_raised(LocalJumpError) {obj.ok} + end + def test_syntax_error_in_rescue bug12613 = '[ruby-core:76531] [Bug #12613]' assert_syntax_error("#{<<-"begin;"}\n#{<<-"end;"}", /Invalid retry/, bug12613)