summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNobuyoshi Nakada <nobu@ruby-lang.org>2023-07-19 12:42:20 +0900
committerNobuyoshi Nakada <nobu@ruby-lang.org>2023-07-19 12:42:20 +0900
commita3a74771f23b4e31c1aaa33e2ffb5ba4a1f51ffe (patch)
treef85af00cb23a46ca7caf97b57a248ddc61f769fc
parent3211b7054562a3435b34311b0811cdf1956443b6 (diff)
Add a corner case for `return`
-rw-r--r--test/ruby/test_syntax.rb10
1 files changed, 10 insertions, 0 deletions
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)