From ef697388becedf36966a2edcdcf88baca342b9e2 Mon Sep 17 00:00:00 2001 From: Jeremy Evans Date: Wed, 2 Oct 2019 07:56:28 -0700 Subject: Treat return in block in class/module as LocalJumpError (#2511) return directly in class/module is an error, so return in proc in class/module should also be an error. I believe the previous behavior was an unintentional oversight during the addition of top-level return in 2.4. --- test/ruby/test_syntax.rb | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'test') diff --git a/test/ruby/test_syntax.rb b/test/ruby/test_syntax.rb index a64d25845a..80bff868f6 100644 --- a/test/ruby/test_syntax.rb +++ b/test/ruby/test_syntax.rb @@ -1272,6 +1272,10 @@ eom assert_warn(/argument of top-level return is ignored/) {eval("return 1")} end + def test_return_in_proc_in_class + assert_in_out_err(['-e', 'class TestSyntax; proc{ return }.call; end'], "", [], /^-e:1:.*unexpected return \(LocalJumpError\)/) + end + def test_syntax_error_in_rescue bug12613 = '[ruby-core:76531] [Bug #12613]' assert_syntax_error("#{<<-"begin;"}\n#{<<-"end;"}", /Invalid retry/, bug12613) -- cgit v1.2.3