summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormame <mame@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2010-01-08 14:10:58 +0000
committermame <mame@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2010-01-08 14:10:58 +0000
commit479a3c4c8b4d6c612a50a6cabab04921378a6f4b (patch)
treede34e24f74d32f7f233b4fd13985114ae3dfccc9
parente0cdab5fff0e57bdea2cb3237e5031dd69fbada5 (diff)
* 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
-rw-r--r--ChangeLog5
-rw-r--r--test/ruby/test_alias.rb19
-rw-r--r--vm_method.c12
3 files changed, 35 insertions, 1 deletions
diff --git a/ChangeLog b/ChangeLog
index 08cb523320..b0dca87b1d 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -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>
* lib/net/http, lib/net/https: move content from net/https to
diff --git a/test/ruby/test_alias.rb b/test/ruby/test_alias.rb
index babd763577..6320121bce 100644
--- a/test/ruby/test_alias.rb
+++ b/test/ruby/test_alias.rb
@@ -85,4 +85,23 @@ class TestAlias < Test::Unit::TestCase
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
diff --git a/vm_method.c b/vm_method.c
index 9e5418afc3..80666b7f19 100644
--- a/vm_method.c
+++ b/vm_method.c
@@ -858,7 +858,9 @@ rb_method_definition_eq(const rb_method_definition_t *d1, const rb_method_defini
void
rb_alias(VALUE klass, ID name, ID def)
{
+ VALUE target_klass = klass;
rb_method_entry_t *orig_me;
+ rb_method_flag_t flag = NOEX_UNDEF;
if (NIL_P(klass)) {
rb_raise(rb_eTypeError, "no class to make alias");
@@ -869,6 +871,7 @@ rb_alias(VALUE klass, ID name, ID def)
rb_secure(4);
}
+ again:
orig_me = search_method(klass, def);
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);
}
}
+ 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);
}
/*