Project

General

Profile

Actions

Bug #11173

closed

inter class/module alias causes "no superclass method"

Added by ko1 (Koichi Sasada) almost 9 years ago. Updated over 8 years ago.

Status:
Closed
Assignee:
-
Target version:
-
[ruby-dev:48992]

Description

class C0
  def foo
    p :C0
  end
end

module M0
  def foo
    p :M0
    super
  end
end

module M1
  include M0
  alias orig_foo foo
end

class C1 < C0
  include M1
end

p C1.ancestors
C1.new.orig_foo

結果:

ruby 2.3.0dev (2015-05-21 trunk 50502) [i386-mswin32_110]
[C1, M1, M0, C0, Object, Kernel, BasicObject]
:M0
test.rb:12:in `foo': super: no superclass method `foo' for #<C1:0x109634c> (NoMethodError)
	from test.rb:26:in `<main>'

M0#foo の super である C0#foo が呼ばれてもいいと思うのですが、
この挙動はそういうもんでしたっけ。

挙動的には、M1 の alias で作られる method_entry が M0 の T_ICLASS (TI1) を指すけど、C1 からの継承関係で作られる M0 を指す T_ICLASS (TI2)と、TI1 が関係ないから、起こっているんだと思います。

なんか、class/module をまたいだ alias の挙動(と、その super での挙動)が色々怪しい感じです。

Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0Like0Like0