diff options
author | usa <usa@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2016-04-22 09:42:21 +0000 |
---|---|---|
committer | usa <usa@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2016-04-22 09:42:21 +0000 |
commit | bb7fa59e0f3d6c535ea2377e92156829f40362de (patch) | |
tree | f1e3180f2733ba6ed14996bbfb0bddb12967a83f /test | |
parent | 3a2effbd6bebfa01abbbf8544543a643d142801c (diff) |
merge revision(s) 54542,54548: [Backport #12082]
* compile.c (iseq_optimize): disable tail call optimization in
rescued, rescue, and ensure blocks.
[ruby-core:73871] [Bug #12082]
* compile.c (new_label_body): initialize bit fields, since
compile_data_alloc does not clear the memory. [Bug #12082]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_2_2@54698 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'test')
-rw-r--r-- | test/ruby/test_optimization.rb | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/test/ruby/test_optimization.rb b/test/ruby/test_optimization.rb index 91b46cc98c..8e350547f3 100644 --- a/test/ruby/test_optimization.rb +++ b/test/ruby/test_optimization.rb @@ -210,6 +210,23 @@ class TestRubyOptimization < Test::Unit::TestCase assert_equal true, MyObj.new == nil end + def self.tailcall(klass, src, file = nil, path = nil, line = nil) + unless file + loc, = caller_locations(1, 1) + file = loc.path + line ||= loc.lineno + end + RubyVM::InstructionSequence.new("proc {|_|_.class_eval {#{src}}}", + file, (path || file), line, + tailcall_optimization: true, + trace_instruction: false) + .eval[klass] + end + + def tailcall(*args) + self.class.tailcall(singleton_class, *args) + end + def test_tailcall bug4082 = '[ruby-core:33289]' @@ -255,6 +272,30 @@ class TestRubyOptimization < Test::Unit::TestCase assert_equal(123, delay { 123 }.call, bug6901) end + def do_raise + raise "should be rescued" + end + + def errinfo + $! + end + + def test_tailcall_inhibited_by_rescue + bug12082 = '[ruby-core:73871] [Bug #12082]' + + tailcall(<<-'end;') + def to_be_rescued + return do_raise + 1 + 2 + rescue + errinfo + end + end; + result = to_be_rescued + assert_instance_of(RuntimeError, result, bug12082) + assert_equal("should be rescued", result.message, bug12082) + end + class Bug10557 def [](_) block_given? |