зеркало из https://github.com/github/ruby.git
* vm_method.c (rb_alias): skip ZSUPER method when searching body of
source method. [ruby-dev:39760] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@26255 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
Родитель
e0cdab5fff
Коммит
479a3c4c8b
|
@ -1,3 +1,8 @@
|
||||||
|
Fri Jan 8 22:59:40 2010 Yusuke Endoh <mame@tsg.ne.jp>
|
||||||
|
|
||||||
|
* vm_method.c (rb_alias): skip ZSUPER method when searching body of
|
||||||
|
source method. [ruby-dev:39760]
|
||||||
|
|
||||||
Fri Jan 8 21:15:21 2010 NARUSE, Yui <naruse@ruby-lang.org>
|
Fri Jan 8 21:15:21 2010 NARUSE, Yui <naruse@ruby-lang.org>
|
||||||
|
|
||||||
* lib/net/http, lib/net/https: move content from net/https to
|
* lib/net/http, lib/net/https: move content from net/https to
|
||||||
|
|
|
@ -85,4 +85,23 @@ class TestAlias < Test::Unit::TestCase
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_alias_with_zsuper_method
|
||||||
|
c = Class.new
|
||||||
|
c.class_eval do
|
||||||
|
def foo
|
||||||
|
:ok
|
||||||
|
end
|
||||||
|
def bar
|
||||||
|
:ng
|
||||||
|
end
|
||||||
|
private :foo
|
||||||
|
end
|
||||||
|
d = Class.new(c)
|
||||||
|
d.class_eval do
|
||||||
|
public :foo
|
||||||
|
alias bar foo
|
||||||
|
end
|
||||||
|
assert_equal(:ok, d.new.bar)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
12
vm_method.c
12
vm_method.c
|
@ -858,7 +858,9 @@ rb_method_definition_eq(const rb_method_definition_t *d1, const rb_method_defini
|
||||||
void
|
void
|
||||||
rb_alias(VALUE klass, ID name, ID def)
|
rb_alias(VALUE klass, ID name, ID def)
|
||||||
{
|
{
|
||||||
|
VALUE target_klass = klass;
|
||||||
rb_method_entry_t *orig_me;
|
rb_method_entry_t *orig_me;
|
||||||
|
rb_method_flag_t flag = NOEX_UNDEF;
|
||||||
|
|
||||||
if (NIL_P(klass)) {
|
if (NIL_P(klass)) {
|
||||||
rb_raise(rb_eTypeError, "no class to make alias");
|
rb_raise(rb_eTypeError, "no class to make alias");
|
||||||
|
@ -869,6 +871,7 @@ rb_alias(VALUE klass, ID name, ID def)
|
||||||
rb_secure(4);
|
rb_secure(4);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
again:
|
||||||
orig_me = search_method(klass, def);
|
orig_me = search_method(klass, def);
|
||||||
|
|
||||||
if (UNDEFINED_METHOD_ENTRY_P(orig_me)) {
|
if (UNDEFINED_METHOD_ENTRY_P(orig_me)) {
|
||||||
|
@ -877,8 +880,15 @@ rb_alias(VALUE klass, ID name, ID def)
|
||||||
rb_print_undef(klass, def, 0);
|
rb_print_undef(klass, def, 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (orig_me->def->type == VM_METHOD_TYPE_ZSUPER) {
|
||||||
|
klass = RCLASS_SUPER(klass);
|
||||||
|
def = orig_me->def->original_id;
|
||||||
|
flag = orig_me->flag;
|
||||||
|
goto again;
|
||||||
|
}
|
||||||
|
|
||||||
rb_add_method_me(klass, name, orig_me, orig_me->flag);
|
if (flag == NOEX_UNDEF) flag = orig_me->flag;
|
||||||
|
rb_add_method_me(target_klass, name, orig_me, flag);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
Загрузка…
Ссылка в новой задаче