Project

General

Profile

Actions

Bug #7993

closed

owner of methods defined after using Module#prepend

Added by no6v (Nobuhiro IMAI) over 11 years ago. Updated almost 11 years ago.

Status:
Closed
Assignee:
-
Target version:
-
ruby -v:
RUBY_DESCRIPTION # => "ruby 2.1.0dev (2013-03-01 trunk 39546) [x86_64-linux]"
[ruby-core:53070]

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 3 (0 open3 closed)

Related to Ruby master - Bug #7987: Method#parameters should consider a prepended or refined methdClosed02/28/2013Actions
Is duplicate of Ruby master - Bug #7842: An alias of a "prepend"ed method skips the original method when calling superClosednobu (Nobuyoshi Nakada)02/13/2013Actions
Has duplicate Ruby master - Bug #8817: Method#owner on prepended classes is an instance rather than Class/Method Closed08/25/2013Actions

Updated by marcandre (Marc-Andre Lafortune) over 11 years ago

Agreed. I described this in [ruby-core:52261], part of issue #7842.

Actions #2

Updated by nobu (Nobuyoshi Nakada) almost 11 years 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.

Updated by nobu (Nobuyoshi Nakada) almost 11 years ago

  • Backport set to 1.9.3: DONTNEED, 2.0.0: REQUIRED

Updated by nagachika (Tomoyuki Chikanaga) almost 11 years 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.

Updated by nobu (Nobuyoshi Nakada) almost 11 years ago

  • Description updated (diff)

Updated by nobu (Nobuyoshi Nakada) over 10 years ago

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

Also available in: Atom PDF

Like0
Like0Like0Like0Like0Like0Like0