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. --- spec/ruby/language/return_spec.rb | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) (limited to 'spec/ruby/language') diff --git a/spec/ruby/language/return_spec.rb b/spec/ruby/language/return_spec.rb index 7f740be25b..7eef6d06ca 100644 --- a/spec/ruby/language/return_spec.rb +++ b/spec/ruby/language/return_spec.rb @@ -443,17 +443,18 @@ describe "The return keyword" do end describe "within a block within a class" do - it "is allowed" do - File.write(@filename, <<-END_OF_CODE) - class ReturnSpecs::A - ScratchPad << "before return" - 1.times { return } - ScratchPad << "after return" - end - END_OF_CODE + ruby_version_is "2.7" do + it "is not allowed" do + File.write(@filename, <<-END_OF_CODE) + class ReturnSpecs::A + ScratchPad << "before return" + 1.times { return } + ScratchPad << "after return" + end + END_OF_CODE - load @filename - ScratchPad.recorded.should == ["before return"] + -> { load @filename }.should raise_error(LocalJumpError) + end end end -- cgit v1.2.3