1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

* vm_insnhelper.c (vm_get_ev_const): search root cref properly.

[ruby-dev:43365]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@31221 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
shugo 2011-03-31 07:52:40 +00:00
parent 3044423f94
commit 4273aa8e72
4 changed files with 52 additions and 19 deletions

View file

@ -1,3 +1,8 @@
Thu Mar 31 16:49:56 2011 Shugo Maeda <shugo@ruby-lang.org>
* vm_insnhelper.c (vm_get_ev_const): search root cref properly.
[ruby-dev:43365]
Thu Mar 31 14:50:25 2011 Shugo Maeda <shugo@ruby-lang.org>
* eval.c (rb_mod_s_constants): should ignore crefs with

View file

@ -137,7 +137,7 @@ assert_equal %q{C}, %q{
}
C.new.m
}
assert_equal %q{C}, %q{
assert_equal %q{top}, %q{
Const = :top
class C
Const = :C

View file

@ -1006,19 +1006,47 @@ class TestModule < Test::Unit::TestCase
assert_in_out_err([], src, %w(Object :ok), [])
end
module A
B = 42
def test_constant_lookup_in_method_defined_by_class_eval
src = <<-INPUT
class A
B = 42
end
A.class_eval do
def self.f
B
end
def f
B
end
end
begin
A.f
rescue NameError
puts "A.f"
end
begin
A.new.f
rescue NameError
puts "A.new.f"
end
INPUT
assert_in_out_err([], src, %w(A.f A.new.f), [])
end
def test_constant_lookup_in_method_defined_by_class_eval
A.class_eval do
def self.f
B
def test_constant_lookup_in_toplevel_class_eval
src = <<-INPUT
module X
A = 123
end
end
assert_raise(NameError) do
A.f
end
begin
X.class_eval { A }
rescue NameError => e
puts e
end
INPUT
assert_in_out_err([], src, ["uninitialized constant A"], [])
end
end

View file

@ -1155,16 +1155,16 @@ vm_get_ev_const(rb_thread_t *th, const rb_iseq_t *iseq,
if (orig_klass == Qnil) {
/* in current lexical scope */
const NODE *cref = vm_get_cref(iseq, th->cfp->lfp, th->cfp->dfp);
const NODE *root_cref = NULL;
const NODE *root_cref = vm_get_cref(iseq, th->cfp->lfp, th->cfp->dfp);
const NODE *cref;
VALUE klass = orig_klass;
while (root_cref && root_cref->flags & NODE_FL_CREF_PUSHED_BY_EVAL) {
root_cref = root_cref->nd_next;
}
cref = root_cref;
while (cref && cref->nd_next) {
if (!(cref->flags & NODE_FL_CREF_PUSHED_BY_EVAL)) {
klass = cref->nd_clss;
if (root_cref == NULL)
root_cref = cref;
}
klass = cref->nd_clss;
cref = cref->nd_next;
if (!NIL_P(klass)) {