mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
* class.c (rewrite_cref_stack, clone_method): rewrite a method's cref
stack when cloning into a new class to allow lexical const lookup to work as expected [ruby-core:47834] [Bug #7107] * test/ruby/test_class.rb (class TestClass): related test git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@38423 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
6d8ad6c489
commit
a70bb8889b
3 changed files with 39 additions and 0 deletions
|
@ -1,3 +1,10 @@
|
||||||
|
Mon Dec 17 18:03:34 2012 Charlie Somerville <charlie@charliesomerville.com>
|
||||||
|
|
||||||
|
* class.c (rewrite_cref_stack, clone_method): rewrite a method's cref
|
||||||
|
stack when cloning into a new class to allow lexical const lookup to
|
||||||
|
work as expected [ruby-core:47834] [Bug #7107]
|
||||||
|
* test/ruby/test_class.rb (class TestClass): related test
|
||||||
|
|
||||||
Mon Dec 17 13:56:55 2012 KOSAKI Motohiro <kosaki.motohiro@gmail.com>
|
Mon Dec 17 13:56:55 2012 KOSAKI Motohiro <kosaki.motohiro@gmail.com>
|
||||||
|
|
||||||
* io.c (io_flush_buffer_sync2): avoid to return 0. because
|
* io.c (io_flush_buffer_sync2): avoid to return 0. because
|
||||||
|
|
18
class.c
18
class.c
|
@ -121,6 +121,23 @@ rb_class_new(VALUE super)
|
||||||
return rb_class_boot(super);
|
return rb_class_boot(super);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static NODE*
|
||||||
|
rewrite_cref_stack(NODE *node, VALUE old_klass, VALUE new_klass)
|
||||||
|
{
|
||||||
|
NODE *new_node;
|
||||||
|
if (!node) {
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
if (node->nd_clss == old_klass) {
|
||||||
|
new_node = NEW_CREF(new_klass);
|
||||||
|
new_node->nd_next = node->nd_next;
|
||||||
|
} else {
|
||||||
|
new_node = NEW_CREF(node->nd_clss);
|
||||||
|
new_node->nd_next = rewrite_cref_stack(node->nd_next, old_klass, new_klass);
|
||||||
|
}
|
||||||
|
return new_node;
|
||||||
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
clone_method(VALUE klass, ID mid, const rb_method_entry_t *me)
|
clone_method(VALUE klass, ID mid, const rb_method_entry_t *me)
|
||||||
{
|
{
|
||||||
|
@ -129,6 +146,7 @@ clone_method(VALUE klass, ID mid, const rb_method_entry_t *me)
|
||||||
rb_iseq_t *iseq;
|
rb_iseq_t *iseq;
|
||||||
newiseqval = rb_iseq_clone(me->def->body.iseq->self, klass);
|
newiseqval = rb_iseq_clone(me->def->body.iseq->self, klass);
|
||||||
GetISeqPtr(newiseqval, iseq);
|
GetISeqPtr(newiseqval, iseq);
|
||||||
|
iseq->cref_stack = rewrite_cref_stack(me->def->body.iseq->cref_stack, me->klass, klass);
|
||||||
rb_add_method(klass, mid, VM_METHOD_TYPE_ISEQ, iseq, me->flag);
|
rb_add_method(klass, mid, VM_METHOD_TYPE_ISEQ, iseq, me->flag);
|
||||||
RB_GC_GUARD(newiseqval);
|
RB_GC_GUARD(newiseqval);
|
||||||
}
|
}
|
||||||
|
|
|
@ -285,4 +285,18 @@ class TestClass < Test::Unit::TestCase
|
||||||
p A.superclass
|
p A.superclass
|
||||||
RUBY
|
RUBY
|
||||||
end
|
end
|
||||||
|
|
||||||
|
module M
|
||||||
|
C = 1
|
||||||
|
|
||||||
|
def self.m
|
||||||
|
C
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_constant_access_from_method_in_cloned_module # [ruby-core:47834]
|
||||||
|
m = M.dup
|
||||||
|
assert_equal 1, m::C
|
||||||
|
assert_equal 1, m.m
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue