Bug #7993

owner of methods defined after using Module#prepend

Added by Nobuhiro IMAI about 1 year ago. Updated 2 months ago.

[ruby-core:53070]
Status:Closed
Priority:Normal
Assignee:-
Category:core
Target version:-
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 ... Closed 02/28/2013
Duplicates ruby-trunk - Bug #7842: An alias of a "prepend"ed method skips the original metho... Closed 02/13/2013
Duplicated by ruby-trunk - Bug #8817: Method#owner on prepended classes is an instance rather t... Closed 08/25/2013

Associated revisions

Revision 44175
Added by Nobuyoshi Nakada 4 months 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.
  • vmmethod.c (rbmethodentrymake, rb_alias): store the originally defined class in me. [Bug #7993] [Bug #7842] [Bug #9236]
  • vmmethod.c (rbmethodentrygetwithoutcache): cache included module but not iclass.

History

#1 Updated by Marc-Andre Lafortune about 1 year ago

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

#2 Updated by Nobuyoshi Nakada 4 months 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.
  • vmmethod.c (rbmethodentrymake, rb_alias): store the originally defined class in me. [Bug #7993] [Bug #7842] [Bug #9236]
  • vmmethod.c (rbmethodentrygetwithoutcache): cache included module but not iclass.

#3 Updated by Nobuyoshi Nakada 4 months ago

  • Backport set to 1.9.3: DONTNEED, 2.0.0: REQUIRED

#4 Updated by Tomoyuki Chikanaga 4 months 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 ruby20_0 at r44345, and additionally r44198 was backported at 44366.
See #9236 too.

#5 Updated by Nobuyoshi Nakada 2 months ago

  • Description updated (diff)

#6 Updated by Nobuyoshi Nakada 1 day ago

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

Also available in: Atom PDF