summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/ruby/test_optimization.rb23
1 files changed, 23 insertions, 0 deletions
diff --git a/test/ruby/test_optimization.rb b/test/ruby/test_optimization.rb
index 8e8311e6ef..ed604e7bc3 100644
--- a/test/ruby/test_optimization.rb
+++ b/test/ruby/test_optimization.rb
@@ -137,4 +137,27 @@ class TestRubyOptimization < Test::Unit::TestCase
assert_equal true, MyObj.new == nil
end
+ def test_tailcall
+ bug4082 = '[ruby-core:33289]'
+
+ option = {
+ tailcall_optimization: true,
+ trace_instruction: false,
+ }
+ iseq = RubyVM::InstructionSequence.new(<<-EOF, "Bug#4082", bug4082, nil, option).eval
+ class #{self.class}::Tailcall
+ def fact_helper(n, res)
+ if n == 1
+ res
+ else
+ fact_helper(n - 1, n * res)
+ end
+ end
+ def fact(n)
+ fact_helper(n, 1)
+ end
+ end
+ EOF
+ assert_equal(9131, Tailcall.new.fact(3000).to_s.size, bug4082)
+ end
end