From 5541561f6a0fc102854abce3554121fb243cdd8d Mon Sep 17 00:00:00 2001 From: nobu Date: Tue, 8 Mar 2016 15:29:48 +0000 Subject: vm_method.c: fix aliased original name * vm_method.c (rb_alias): the original name should be properly available method_added method, set the name before calling the hook. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@54035 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ChangeLog | 6 ++++++ test/ruby/test_alias.rb | 28 ++++++++++++++++++++++++++++ vm_method.c | 8 ++++---- 3 files changed, 38 insertions(+), 4 deletions(-) diff --git a/ChangeLog b/ChangeLog index f1dd0aec1f..897d7a89cf 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +Wed Mar 9 00:29:46 2016 Nobuyoshi Nakada + + * vm_method.c (rb_alias): the original name should be properly + available method_added method, set the name before calling the + hook. + Wed Mar 9 00:07:03 2016 Nobuyoshi Nakada * lib/logger.rb (Logger::LogDevice#initialize): define using diff --git a/test/ruby/test_alias.rb b/test/ruby/test_alias.rb index d5bbce3dda..3fc1bb4000 100644 --- a/test/ruby/test_alias.rb +++ b/test/ruby/test_alias.rb @@ -203,4 +203,32 @@ class TestAlias < Test::Unit::TestCase assert_equal(obj.method(:bar), obj.method(:foo)) assert_equal(obj.method(:foo), obj.method(:bar)) end + + def test_alias_class_method_added + name = nil + k = Class.new { + def foo;end + def self.method_added(mid) + @name = instance_method(mid).original_name + end + alias bar foo + name = @name + } + assert_equal(:foo, k.instance_method(:bar).original_name) + assert_equal(:foo, name) + end + + def test_alias_module_method_added + name = nil + k = Module.new { + def foo;end + def self.method_added(mid) + @name = instance_method(mid).original_name + end + alias bar foo + name = @name + } + assert_equal(:foo, k.instance_method(:bar).original_name) + assert_equal(:foo, name) + end end diff --git a/vm_method.c b/vm_method.c index bbe7bebaa9..2d3e78c303 100644 --- a/vm_method.c +++ b/vm_method.c @@ -1552,10 +1552,10 @@ rb_alias(VALUE klass, ID alias_name, ID original_name) if (visi == METHOD_VISI_UNDEF) visi = METHOD_ENTRY_VISI(orig_me); if (orig_me->defined_class == 0) { - rb_method_entry_t *alias_me; - - alias_me = rb_add_method(target_klass, alias_name, VM_METHOD_TYPE_ALIAS, (void *)rb_method_entry_clone(orig_me), visi); - alias_me->def->original_id = orig_me->called_id; + rb_method_entry_make(target_klass, alias_name, target_klass, visi, + VM_METHOD_TYPE_ALIAS, NULL, orig_me->called_id, + (void *)rb_method_entry_clone(orig_me)); + method_added(target_klass, alias_name); } else { rb_method_entry_t *alias_me; -- cgit v1.2.3