Project

General

Profile

Actions

Bug #13656

closed

Method#super_method returns incorrect result dependent on unrelated module

Added by ccutrer (Cody Cutrer) almost 7 years ago. Updated over 6 years ago.

Status:
Closed
Assignee:
-
Target version:
-
ruby -v:
ruby 2.4.1p111 (2017-03-22 revision 58053) [x86_64-darwin16]
[ruby-core:81666]

Description

module Calculations
  def pluck
     puts "calculations"
  end
end

module Calculations2
  def pluck
    puts "calculations2"
    super
  end
end

class Relation
  include Calculations
end

Relation.prepend(Calculations2)

class CollectionProxy < Relation
  def pluck
    puts "collection_proxy"
    super
  end
end

module CollectionProxy2
  def unrelated
  end
end

# this is the critical line
CollectionProxy.prepend(CollectionProxy2)

ConcreteProxy = Class.new(CollectionProxy)

# these are the expected results
ConcreteProxy.new.method(:pluck).owner == CollectionProxy
ConcreteProxy.new.method(:pluck).super_method.owner == Calculations2
ConcreteProxy.new.method(:pluck).super_method.super_method.owner == Calculations

The critical line is the CollectionProxy2 module. If I don't prepend it into CollectionProxy (or if I include it instead of prepend it), the expected results pass. But when it is prepended, the owner for all super_methods will always be CollectionProxy, as if it can't find any more ancestors (if you actually call ConcreteProxy.new.pluck it does call the three methods, in the correct order). So this is an introspection only problem.

Actions #1

Updated by nobu (Nobuyoshi Nakada) almost 7 years ago

  • Description updated (diff)
  • Backport changed from 2.2: UNKNOWN, 2.3: UNKNOWN, 2.4: UNKNOWN to 2.2: REQUIRED, 2.3: REQUIRED, 2.4: REQUIRED
Actions #2

Updated by nobu (Nobuyoshi Nakada) almost 7 years ago

  • Status changed from Open to Closed

Applied in changeset trunk|r59080.


proc.c: skip prepended modules

  • proc.c (method_super_method): skip prepended modules and
    continue from the super class of the original class.
    [ruby-core:81666] [Bug #13656]

Updated by usa (Usaku NAKAMURA) almost 7 years ago

  • Backport changed from 2.2: REQUIRED, 2.3: REQUIRED, 2.4: REQUIRED to 2.2: REQUIRED, 2.3: DONE, 2.4: REQUIRED

ruby_2_3 r59231 merged revision(s) 59080,59082.

Updated by nagachika (Tomoyuki Chikanaga) over 6 years ago

  • Backport changed from 2.2: REQUIRED, 2.3: DONE, 2.4: REQUIRED to 2.2: REQUIRED, 2.3: DONE, 2.4: DONE

ruby_2_4 r59395 merged revision(s) 59080,59082.

Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0