summaryrefslogtreecommitdiff
path: root/vm_insnhelper.c
diff options
context:
space:
mode:
authorshugo <shugo@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2012-12-10 16:05:45 +0000
committershugo <shugo@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2012-12-10 16:05:45 +0000
commit7ef16d224a80a6e1e8c01b5b45ac7e2315a04e4c (patch)
treec0ac99c10c8f3d5a9e9529de1460575ae8f4d401 /vm_insnhelper.c
parentfa7c4ab4084ac6d5ad615d133ab0dcaca2c817fb (diff)
* fix the behavior when a module is included into a refinement.
This change is a little tricky, so it might be better to prohibit module inclusion to refinements. * include/ruby/ruby.h (RMODULE_INCLUDED_INTO_REFINEMENT): new flag to represent that a module (iclass) is included into a refinement. * class.c (include_modules_at): set RMODULE_INCLUDED_INTO_REFINEMENT if klass is a refinement. * eval.c (rb_mod_refine): set the superclass of a refinement to the refined class for super. * eval.c (rb_using_refinement): skip the above superclass (the refined class) when creating iclasses for refinements. Otherwise, `using Refinement1; using Refinement2' creates iclasses: <Refinement2> -> <RefinedClass> -> <Refinement1> -> RefinedClass, where <Module> is an iclass for Module, so RefinedClass is searched before Refinement1. The correct iclasses should be <Refinement2> -> <Refinement1> -> RefinedClass. * vm_insnhelper.c (vm_search_normal_superclass): if klass is an iclass for a refinement, use the refinement's superclass instead of the iclass's superclass. Otherwise, multiple refinements are searched by super. For example, if a refinement Refinement2 includes a module M (i.e., Refinement2 -> <M> -> RefinedClass, and if refinements iclasses are <Refinement2> -> <M>' -> <Refinement1> -> RefinedClass, then super in <Refinement2> should use Refinement2's superclass <M> instead of <Refinement2>'s superclass <M>'. * vm_insnhelper.c (vm_search_super_method): do not raise a NotImplementError if current_defind_class is a module included into a refinement. Because of the change of vm_search_normal_superclass(), the receiver might not be an instance of the module('s iclass). * test/ruby/test_refinement.rb: related test. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@38298 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'vm_insnhelper.c')
-rw-r--r--vm_insnhelper.c11
1 files changed, 5 insertions, 6 deletions
diff --git a/vm_insnhelper.c b/vm_insnhelper.c
index ff59a609e5..1470844309 100644
--- a/vm_insnhelper.c
+++ b/vm_insnhelper.c
@@ -1866,12 +1866,10 @@ vm_search_normal_superclass(VALUE klass)
{
if (BUILTIN_TYPE(klass) == T_ICLASS &&
FL_TEST(RBASIC(klass)->klass, RMODULE_IS_REFINEMENT)) {
- return rb_refinement_module_get_refined_class(RBASIC(klass)->klass);
- }
- else {
- klass = RCLASS_ORIGIN(klass);
- return RCLASS_SUPER(klass);
+ klass = RBASIC(klass)->klass;
}
+ klass = RCLASS_ORIGIN(klass);
+ return RCLASS_SUPER(klass);
}
static void
@@ -1945,7 +1943,8 @@ vm_search_super_method(rb_thread_t *th, rb_control_frame_t *reg_cfp, rb_call_inf
current_defind_class = RCLASS_REFINED_CLASS(current_defind_class);
}
- if (!rb_obj_is_kind_of(ci->recv, current_defind_class)) {
+ if (!FL_TEST(current_defind_class, RMODULE_INCLUDED_INTO_REFINEMENT) &&
+ !rb_obj_is_kind_of(ci->recv, current_defind_class)) {
rb_raise(rb_eNotImpError, "super from singleton method that is defined to multiple classes is not supported; this will be fixed in 2.0.0 or later");
}