* 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
This commit is contained in:
parent
e3990633cb
commit
de14055d62
@ -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>
|
Fri Sep 28 15:15:41 2012 Koichi Sasada <ko1@atdot.net>
|
||||||
|
|
||||||
* insns.def (opt_checkenv): remove unused instruction `opt_checkenv'.
|
* insns.def (opt_checkenv): remove unused instruction `opt_checkenv'.
|
||||||
|
@ -361,6 +361,24 @@ class TestRefinement < Test::Unit::TestCase
|
|||||||
assert_equal([:m1, :m2], m2.module_eval { obj.foo })
|
assert_equal([:m1, :m2], m2.module_eval { obj.foo })
|
||||||
end
|
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
|
def test_refine_neither_class_nor_module
|
||||||
assert_raise(TypeError) do
|
assert_raise(TypeError) do
|
||||||
Module.new {
|
Module.new {
|
||||||
|
31
vm_method.c
31
vm_method.c
@ -376,6 +376,24 @@ rb_get_alloc_func(VALUE klass)
|
|||||||
return 0;
|
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*
|
static rb_method_entry_t*
|
||||||
search_method(VALUE klass, ID id, VALUE omod, VALUE *defined_class_ptr)
|
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;
|
st_table *m_tbl;
|
||||||
|
|
||||||
if (!NIL_P(omod) && klass != skipped_class) {
|
if (!NIL_P(omod) && klass != skipped_class) {
|
||||||
VALUE c;
|
iclass = rb_hash_lookup(omod, klass);
|
||||||
|
if (NIL_P(iclass) && BUILTIN_TYPE(klass) == T_ICLASS) {
|
||||||
if (BUILTIN_TYPE(klass) == T_ICLASS) {
|
iclass = rb_hash_lookup(omod, RBASIC(klass)->klass);
|
||||||
c = RBASIC(klass)->klass;
|
if (!NIL_P(iclass))
|
||||||
|
iclass = copy_refinement_iclass(iclass, klass);
|
||||||
}
|
}
|
||||||
else {
|
|
||||||
c = klass;
|
|
||||||
}
|
|
||||||
iclass = rb_hash_lookup(omod, c);
|
|
||||||
if (!NIL_P(iclass)) {
|
if (!NIL_P(iclass)) {
|
||||||
skipped_class = klass;
|
skipped_class = klass;
|
||||||
klass = iclass;
|
klass = iclass;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user