1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

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
This commit is contained in:
nobu 2016-03-08 15:29:48 +00:00
parent 3c4ade2019
commit 6cde2d359a
3 changed files with 38 additions and 4 deletions

View file

@ -1,3 +1,9 @@
Wed Mar 9 00:29:46 2016 Nobuyoshi Nakada <nobu@ruby-lang.org>
* 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 <nobu@ruby-lang.org>
* lib/logger.rb (Logger::LogDevice#initialize): define using

View file

@ -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

View file

@ -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;