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

ruby-changes:60473

From: Jeremy <ko1@a...>
Date: Mon, 23 Mar 2020 01:30:35 +0900 (JST)
Subject: [ruby-changes:60473] adecd43197 (master): Merge pull request #2721 from jeremyevans/method-inspect-chain-alias-11188

https://git.ruby-lang.org/ruby.git/commit/?id=adecd43197

From adecd43197d5ea2a62a618a5c9be653bcf009c62 Mon Sep 17 00:00:00 2001
From: Jeremy Evans <code@j...>
Date: Sun, 22 Mar 2020 09:30:20 -0700
Subject: Merge pull request #2721 from
 jeremyevans/method-inspect-chain-alias-11188

Correctly show defined class for aliases of aliases

diff --git a/proc.c b/proc.c
index 9a4aaf4..9164c27 100644
--- a/proc.c
+++ b/proc.c
@@ -1657,8 +1657,8 @@ method_entry_defined_class(const rb_method_entry_t *me) https://github.com/ruby/ruby/blob/trunk/proc.c#L1657
  *   meth == other_meth  -> true or false
  *
  * Two method objects are equal if they are bound to the same
- * object and refer to the same method definition and their owners are the
- * same class or module.
+ * object and refer to the same method definition and the classes
+ * defining the methods are the same class or module.
  */
 
 static VALUE
diff --git a/test/ruby/test_alias.rb b/test/ruby/test_alias.rb
index 33fb82e..271d552 100644
--- a/test/ruby/test_alias.rb
+++ b/test/ruby/test_alias.rb
@@ -35,6 +35,18 @@ class TestAlias < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_alias.rb#L35
     end
   end
 
+  class Alias4 < Alias0
+    alias foo1 foo
+    alias foo2 foo1
+    alias foo3 foo2
+  end
+
+  class Alias5 < Alias4
+    alias foo1 foo
+    alias foo3 foo2
+    alias foo2 foo1
+  end
+
   def test_alias
     x = Alias2.new
     assert_equal "foo", x.bar
@@ -47,6 +59,20 @@ class TestAlias < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_alias.rb#L59
     assert_raise(NoMethodError) { x.quux }
   end
 
+  def test_alias_inspect
+    o = Alias4.new
+    assert_equal("TestAlias::Alias4(TestAlias::Alias0)#foo()", o.method(:foo).inspect.split[1])
+    assert_equal("TestAlias::Alias4(TestAlias::Alias0)#foo1(foo)()", o.method(:foo1).inspect.split[1])
+    assert_equal("TestAlias::Alias4(TestAlias::Alias0)#foo2(foo)()", o.method(:foo2).inspect.split[1])
+    assert_equal("TestAlias::Alias4(TestAlias::Alias0)#foo3(foo)()", o.method(:foo3).inspect.split[1])
+
+    o = Alias5.new
+    assert_equal("TestAlias::Alias5(TestAlias::Alias0)#foo()", o.method(:foo).inspect.split[1])
+    assert_equal("TestAlias::Alias5(TestAlias::Alias0)#foo1(foo)()", o.method(:foo1).inspect.split[1])
+    assert_equal("TestAlias::Alias5(TestAlias::Alias0)#foo2(foo)()", o.method(:foo2).inspect.split[1])
+    assert_equal("TestAlias::Alias5(TestAlias::Alias0)#foo3(foo)()", o.method(:foo3).inspect.split[1])
+  end
+
   def test_nonexistmethod
     assert_raise(NameError){
       Class.new{
diff --git a/test/ruby/test_method.rb b/test/ruby/test_method.rb
index 01a6905..12f6f9a 100644
--- a/test/ruby/test_method.rb
+++ b/test/ruby/test_method.rb
@@ -828,7 +828,7 @@ class TestMethod < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_method.rb#L828
     assert_equal(c, c.instance_method(:foo).owner)
     assert_equal(c, x.method(:foo).owner)
     assert_equal(x.singleton_class, x.method(:bar).owner)
-    assert_not_equal(x.method(:foo), x.method(:bar), bug7613)
+    assert_equal(x.method(:foo), x.method(:bar), bug7613)
     assert_equal(c, x.method(:zot).owner, bug7993)
     assert_equal(c, c.instance_method(:zot).owner, bug7993)
   end
diff --git a/vm_method.c b/vm_method.c
index cce2846..de58f7d 100644
--- a/vm_method.c
+++ b/vm_method.c
@@ -1807,7 +1807,7 @@ rb_alias(VALUE klass, ID alias_name, ID original_name) https://github.com/ruby/ruby/blob/trunk/vm_method.c#L1807
 
 	alias_me = method_entry_set(target_klass, alias_name, orig_me, visi, orig_me->owner);
 	RB_OBJ_WRITE(alias_me, &alias_me->owner, target_klass);
-	RB_OBJ_WRITE(alias_me, &alias_me->defined_class, defined_class);
+        RB_OBJ_WRITE(alias_me, &alias_me->defined_class, orig_me->defined_class);
     }
 }
 
-- 
cgit v0.10.2


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

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