Project

General

Profile

Bug #9475

Behavior change with include + super + alias_method between 1.9.x and 2.x

Added by benweint (Ben Weintraub) about 3 years ago. Updated almost 3 years ago.

Status:
Closed
Priority:
Normal
Target version:
-
ruby -v:
ruby 2.1.0p0 (2013-12-25 revision 44422) [x86_64-darwin12.0]
[ruby-core:60431]

Description

Ruby 2.0 appears to have introduced a subtle behavior change in method resolution that persists in 2.1.0.

The attached test case (also visible online at https://gist.github.com/benweint/8791007) is extracted from an actual application, and while I won't defend the need to do something like this, it is clear that the behavior changed in 2.0. Note that this sounds similar to https://bugs.ruby-lang.org/issues/9236 but is in fact distinct - the test case given in that bug was fixed in Ruby 2.1.

Steps to reproduce:
1. Run the attached testcase on Ruby 1.9.3 note the output
2. Run the attached testcase on Ruby 2.0.0-p353 or 2.1.0-p0, and note the output

Expected results:
While it's certainly not obvious to me what 'should' happen when executing this code, on 1.9.3, it produces this output:

foo from C
foo from B
foo from A  

Actual results:
On 2.0+, I get this instead

foo from C
foo from B
foo from B (again)
foo from B
foo from B (again)
foo from B
... previous two lines repeated many times ...
test.rb:11: stack level too deep (SystemStackError)

That is to say, on 2.0, we get into an infinitely recursive loop that doesn't happen with 1.9.3.

test.rb View (340 Bytes) benweint (Ben Weintraub), 02/03/2014 08:21 PM


Related issues

Related to Ruby trunk - Bug #9663: Segfault with alias_method and include Closed 03/22/2014

Associated revisions

Revision 45367
Added by nobu (Nobuyoshi Nakada) about 3 years ago

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. [Bug #9475]

Revision 45367
Added by nobu (Nobuyoshi Nakada) about 3 years ago

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. [Bug #9475]

Revision 45367
Added by nobu (Nobuyoshi Nakada) about 3 years ago

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. [Bug #9475]

Revision 45367
Added by nobu (Nobuyoshi Nakada) about 3 years ago

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. [Bug #9475]

Revision 45955
Added by nagachika (Tomoyuki Chikanaga) almost 3 years ago

merge revision(s) r45367,r45387,r45388,r45389: [Backport #9475]

* 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.
   [Bug #9475]

* vm_method.c (rb_method_entry_get_without_cache): me->klass is 0
  for a method aliased in a module.   [Bug #9663]

History

#1 [ruby-core:60443] Updated by nobu (Nobuyoshi Nakada) about 3 years ago

  • Assignee set to nobu (Nobuyoshi Nakada)
  • Status changed from Open to Assigned

#2 [ruby-core:61601] Updated by nobu (Nobuyoshi Nakada) about 3 years ago

  • % Done changed from 0 to 100
  • Status changed from Assigned to Closed

Applied in changeset r45367.


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. [Bug #9475]

#3 [ruby-core:61602] Updated by nobu (Nobuyoshi Nakada) about 3 years ago

  • Backport changed from 1.9.3: UNKNOWN, 2.0.0: UNKNOWN, 2.1: UNKNOWN to 1.9.3: REQUIRED, 2.0.0: REQUIRED, 2.1: REQUIRED

#4 [ruby-core:61603] Updated by nobu (Nobuyoshi Nakada) about 3 years ago

  • Description updated (diff)
  • Backport changed from 1.9.3: REQUIRED, 2.0.0: REQUIRED, 2.1: REQUIRED to 1.9.3: DONTNEED, 2.0.0: REQUIRED, 2.1: REQUIRED

#5 [ruby-core:61646] Updated by nagachika (Tomoyuki Chikanaga) about 3 years ago

  • Related to Bug #9663: Segfault with alias_method and include added

#6 [ruby-core:62245] Updated by usa (Usaku NAKAMURA) almost 3 years ago

  • Backport changed from 1.9.3: DONTNEED, 2.0.0: REQUIRED, 2.1: REQUIRED to 1.9.3: DONTNEED, 2.0.0: DONE, 2.1: REQUIRED

backported r45367, r45387, r45388 and r45389 into ruby_2_0_0 at r45750.

#7 [ruby-core:62606] Updated by nagachika (Tomoyuki Chikanaga) almost 3 years ago

  • Backport changed from 1.9.3: DONTNEED, 2.0.0: DONE, 2.1: REQUIRED to 1.9.3: DONTNEED, 2.0.0: DONE, 2.1: DONE

r45367, r45387, r45388 and r45389 were backported into ruby_2_1 branch at r45955.

Also available in: Atom PDF