Bug #7993

owner of methods defined after using Module#prepend

Added by Nobuhiro IMAI over 2 years ago. Updated over 1 year ago.

[ruby-core:53070]
Status:Closed
Priority:Normal
Assignee:-
ruby -v:RUBY_DESCRIPTION # => "ruby 2.1.0dev (2013-03-01 trunk 39546) [x86_64-linux]" Backport:1.9.3: DONTNEED, 2.0.0: DONE

Description

The owner of methods defined after using Module#prepend seems to be incorrect.

RUBY_DESCRIPTION # => "ruby 2.1.0dev (2013-03-01 trunk 39546) [x86_64-linux]"

class C
  attr_reader :a
  prepend Module.new
  attr_reader :b
end
C.instance_method(:a).owner # => C
C.instance_method(:b).owner # => #<C:0x00000000a52300>
C.new.method(:a).owner      # => C
C.new.method(:b).owner      # => #<C:0x00000000a52300>

module M
  attr_reader :a
  prepend Module.new
  attr_reader :b
end
M.instance_method(:a).owner # => M
M.instance_method(:b).owner # =>
# ~> -:19:in `<main>': undefined method `class' for #<M:0x00000000a515b8> (NoMethodError)

Related issues

Related to Ruby trunk - Bug #7987: Method#parameters should consider a prepended or refined methd Closed 02/28/2013
Duplicates Ruby trunk - Bug #7842: An alias of a "prepend"ed method skips the original method when calling super Closed 02/13/2013
Duplicated by Ruby trunk - Bug #8817: Method#owner on prepended classes is an instance rather than Class/Method Closed 08/25/2013

Associated revisions

Revision 44175
Added by Nobuyoshi Nakada over 1 year ago

proc.c, vm_method.c: fix super and alias

  • proc.c (method_owner): return the class where alias is defined, not the class original method is defined.
  • vm_method.c (rb_method_entry_make, rb_alias): store the originally defined class in me. [Bug #7993] [Bug #7842] [Bug #9236]
  • vm_method.c (rb_method_entry_get_without_cache): cache included module but not iclass.

Revision 44175
Added by Nobuyoshi Nakada over 1 year ago

proc.c, vm_method.c: fix super and alias

  • proc.c (method_owner): return the class where alias is defined, not the class original method is defined.
  • vm_method.c (rb_method_entry_make, rb_alias): store the originally defined class in me. [Bug #7993] [Bug #7842] [Bug #9236]
  • vm_method.c (rb_method_entry_get_without_cache): cache included module but not iclass.

History

#1 Updated by Marc-Andre Lafortune over 2 years ago

Agreed. I described this in , part of issue #7842.

#2 Updated by Nobuyoshi Nakada over 1 year ago

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

This issue was solved with changeset r44175.
Nobuhiro, thank you for reporting this issue.
Your contribution to Ruby is greatly appreciated.
May Ruby be with you.


proc.c, vm_method.c: fix super and alias

  • proc.c (method_owner): return the class where alias is defined, not the class original method is defined.
  • vm_method.c (rb_method_entry_make, rb_alias): store the originally defined class in me. [Bug #7993] [Bug #7842] [Bug #9236]
  • vm_method.c (rb_method_entry_get_without_cache): cache included module but not iclass.

#3 Updated by Nobuyoshi Nakada over 1 year ago

  • Backport set to 1.9.3: DONTNEED, 2.0.0: REQUIRED

#4 Updated by Tomoyuki Chikanaga over 1 year ago

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

r44175 and r44179 were backported to ruby_2_0_0 at r44345, and additionally r44198 was backported at 44366.
See #9236 too.

#5 Updated by Nobuyoshi Nakada over 1 year ago

  • Description updated (diff)

#6 Updated by Nobuyoshi Nakada about 1 year ago

  • Related to Bug #7987: Method#parameters should consider a prepended or refined methd added

Also available in: Atom PDF