From 0fcfc7626fcf850a406aa7dffaf6e1ff66539d9d Mon Sep 17 00:00:00 2001 From: nobu Date: Wed, 21 Dec 2016 01:58:32 +0000 Subject: compile.c: toplevel return * compile.c (iseq_compile_each): stop execution of the current source by toplevel return. [ruby-core:36785] [Feature #4840] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@57132 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- test/ruby/test_syntax.rb | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) (limited to 'test/ruby/test_syntax.rb') diff --git a/test/ruby/test_syntax.rb b/test/ruby/test_syntax.rb index f3db9bcd48..3e6212e27c 100644 --- a/test/ruby/test_syntax.rb +++ b/test/ruby/test_syntax.rb @@ -926,6 +926,29 @@ eom assert_equal(:ok, result) end + def test_return_toplevel + feature4840 = '[ruby-core:36785] [Feature #4840]' + code = "#{<<~"begin;"}\n#{<<~"end;"}" + begin; + return; raise + begin return; rescue SystemExit; exit false; end + begin return; ensure exit false; end + begin ensure return; end + begin raise; ensure; return; end + begin raise; rescue; return; end + return false; raise + return 1; raise + end; + all_assertions(feature4840) do |a| + code.each_line do |s| + s.chomp! + a.for(s) do + assert_ruby_status([], s, proc {RubyVM::InstructionSequence.compile(s).disasm}) + end + end + end + end + private def not_label(x) @result = x; @not_label ||= nil end -- cgit v1.2.3