[前][次][番号順一覧][スレッド一覧]

ruby-changes:46965

From: nobu <ko1@a...>
Date: Wed, 14 Jun 2017 15:04:01 +0900 (JST)
Subject: [ruby-changes:46965] nobu:r59080 (trunk): proc.c: skip prepended modules

nobu	2017-06-14 15:03:55 +0900 (Wed, 14 Jun 2017)

  New Revision: 59080

  https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=59080

  Log:
    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]

  Modified files:
    trunk/proc.c
    trunk/test/ruby/test_method.rb
Index: test/ruby/test_method.rb
===================================================================
--- test/ruby/test_method.rb	(revision 59079)
+++ test/ruby/test_method.rb	(revision 59080)
@@ -901,6 +901,17 @@ class TestMethod < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_method.rb#L901
     assert_nil(m)
   end
 
+  def test_super_method_with_prepended_module
+    bug = '[ruby-core:81666] [Bug #13656]'
+    c1 = EnvUtil.labeled_class("C1") {def m; end}
+    c2 = EnvUtil.labeled_class("C2", c1) {def m; end}
+    c2.prepend(EnvUtil.labeled_module("M"))
+    m = c2.instance_method(:m)
+    assert_equal(c2, m.owner)
+    m = m.super_method
+    assert_equal(c1, m.owner, bug)
+  end
+
   def rest_parameter(*rest)
     rest
   end
Index: proc.c
===================================================================
--- proc.c	(revision 59079)
+++ proc.c	(revision 59080)
@@ -2652,7 +2652,7 @@ method_super_method(VALUE method) https://github.com/ruby/ruby/blob/trunk/proc.c#L2652
     const rb_method_entry_t *me;
 
     TypedData_Get_Struct(method, struct METHOD, &method_data_type, data);
-    super_class = RCLASS_SUPER(method_entry_defined_class(data->me));
+    super_class = RCLASS_SUPER(RCLASS_ORIGIN(method_entry_defined_class(data->me)));
     if (!super_class) return Qnil;
     me = (rb_method_entry_t *)rb_callable_method_entry_without_refinements(super_class, data->me->called_id);
     if (!me) return Qnil;

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]