summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorshugo <shugo@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2012-09-28 06:48:20 +0000
committershugo <shugo@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2012-09-28 06:48:20 +0000
commitde14055d62da51b91f9883ae1b3af2ae247565be (patch)
treeffde2455117a6526933ef58ba6da4442231caf42
parente3990633cb2e44f19588c16a436516a8ecae0459 (diff)
* vm_method.c (search_method): copy refinement iclasses to search
superclasses correctly. * test/ruby/test_refinement.rb: related test. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@37046 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r--ChangeLog7
-rw-r--r--test/ruby/test_refinement.rb18
-rw-r--r--vm_method.c31
3 files changed, 48 insertions, 8 deletions
diff --git a/ChangeLog b/ChangeLog
index 5ac7be4255..5451553564 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+Fri Sep 28 15:44:45 2012 Shugo Maeda <shugo@ruby-lang.org>
+
+ * vm_method.c (search_method): copy refinement iclasses to search
+ superclasses correctly.
+
+ * test/ruby/test_refinement.rb: related test.
+
Fri Sep 28 15:15:41 2012 Koichi Sasada <ko1@atdot.net>
* insns.def (opt_checkenv): remove unused instruction `opt_checkenv'.
diff --git a/test/ruby/test_refinement.rb b/test/ruby/test_refinement.rb
index ac6df929f0..98645745e9 100644
--- a/test/ruby/test_refinement.rb
+++ b/test/ruby/test_refinement.rb
@@ -361,6 +361,24 @@ class TestRefinement < Test::Unit::TestCase
assert_equal([:m1, :m2], m2.module_eval { obj.foo })
end
+ def test_refine_module_and_call_superclass_method
+ m1 = Module.new
+ c1 = Class.new {
+ def foo
+ "c1#foo"
+ end
+ }
+ c2 = Class.new(c1) {
+ include m1
+ }
+ m2 = Module.new {
+ refine m1 do
+ end
+ }
+ obj = c2.new
+ assert_equal("c1#foo", m2.module_eval { obj.foo })
+ end
+
def test_refine_neither_class_nor_module
assert_raise(TypeError) do
Module.new {
diff --git a/vm_method.c b/vm_method.c
index bf605e6f67..e44782ce6d 100644
--- a/vm_method.c
+++ b/vm_method.c
@@ -376,6 +376,24 @@ rb_get_alloc_func(VALUE klass)
return 0;
}
+static VALUE
+copy_refinement_iclass(VALUE iclass, VALUE superclass)
+{
+ VALUE result, c;
+
+ Check_Type(iclass, T_ICLASS);
+ c = result = rb_include_class_new(RBASIC(iclass)->klass, superclass);
+ RCLASS_REFINED_CLASS(c) = RCLASS_REFINED_CLASS(iclass);
+ iclass = RCLASS_SUPER(iclass);
+ while (iclass && BUILTIN_TYPE(iclass) == T_ICLASS) {
+ c = RCLASS_SUPER(c) = rb_include_class_new(RBASIC(iclass)->klass,
+ RCLASS_SUPER(c));
+ RCLASS_REFINED_CLASS(c) = RCLASS_REFINED_CLASS(iclass);
+ iclass = RCLASS_SUPER(iclass);
+ }
+ return result;
+}
+
static rb_method_entry_t*
search_method(VALUE klass, ID id, VALUE omod, VALUE *defined_class_ptr)
{
@@ -386,15 +404,12 @@ search_method(VALUE klass, ID id, VALUE omod, VALUE *defined_class_ptr)
st_table *m_tbl;
if (!NIL_P(omod) && klass != skipped_class) {
- VALUE c;
-
- if (BUILTIN_TYPE(klass) == T_ICLASS) {
- c = RBASIC(klass)->klass;
- }
- else {
- c = klass;
+ iclass = rb_hash_lookup(omod, klass);
+ if (NIL_P(iclass) && BUILTIN_TYPE(klass) == T_ICLASS) {
+ iclass = rb_hash_lookup(omod, RBASIC(klass)->klass);
+ if (!NIL_P(iclass))
+ iclass = copy_refinement_iclass(iclass, klass);
}
- iclass = rb_hash_lookup(omod, c);
if (!NIL_P(iclass)) {
skipped_class = klass;
klass = iclass;