From 3453070fbc7e1d4294b6248ceebe22b7577d63dd Mon Sep 17 00:00:00 2001 From: nobu Date: Thu, 20 Mar 2014 03:31:28 +0000 Subject: vm_method.c: fix infinite recursion * vm_method.c (rb_method_entry_get_without_cache): get rid of infinite recursion at aliases in a subclass and a superclass. return actually defined class for other than singleton class. [ruby-core:60431] [Bug #9475] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@45367 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- test/ruby/test_alias.rb | 47 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) (limited to 'test') diff --git a/test/ruby/test_alias.rb b/test/ruby/test_alias.rb index 956fdb41f0..4e1db2e13f 100644 --- a/test/ruby/test_alias.rb +++ b/test/ruby/test_alias.rb @@ -132,4 +132,51 @@ class TestAlias < Test::Unit::TestCase GC.verify_internal_consistency } end + + def test_cyclic_zsuper + bug9475 = '[ruby-core:60431] [Bug #9475]' + + a = Module.new do + def foo + "A" + end + end + + b = Class.new do + include a + attr_reader :b + + def foo + @b ||= 0 + raise SystemStackError if (@b += 1) > 1 + # "foo from B" + super + "B" + end + end + + c = Class.new(b) do + alias orig_foo foo + + def foo + # "foo from C" + orig_foo + "C" + end + end + + b.class_eval do + alias orig_foo foo + attr_reader :b2 + + def foo + @b2 ||= 0 + raise SystemStackError if (@b2 += 1) > 1 + # "foo from B (again)" + orig_foo + "B2" + end + end + + assert_nothing_raised(SystemStackError, bug9475) do + assert_equal("ABC", c.new.foo, bug9475) + end + end end -- cgit v1.2.3