diff options
author | shugo <shugo@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2011-03-31 07:52:40 +0000 |
---|---|---|
committer | shugo <shugo@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2011-03-31 07:52:40 +0000 |
commit | 4273aa8e722c88b04ff0828b6a3c9e6b25988231 (patch) | |
tree | 343e998ef902e2ef978e2b376191ed9f205f76a5 | |
parent | 3044423f9404af026305c18ef40a1460f1dd8308 (diff) |
* 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
-rw-r--r-- | ChangeLog | 5 | ||||
-rw-r--r-- | bootstraptest/test_eval.rb | 2 | ||||
-rw-r--r-- | test/ruby/test_module.rb | 50 | ||||
-rw-r--r-- | vm_insnhelper.c | 14 |
4 files changed, 52 insertions, 19 deletions
@@ -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 diff --git a/bootstraptest/test_eval.rb b/bootstraptest/test_eval.rb index 9ae50a6d30..c347d50ac9 100644 --- a/bootstraptest/test_eval.rb +++ b/bootstraptest/test_eval.rb @@ -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 diff --git a/test/ruby/test_module.rb b/test/ruby/test_module.rb index 6a7f566ac7..6d28616d86 100644 --- a/test/ruby/test_module.rb +++ b/test/ruby/test_module.rb @@ -1006,19 +1006,47 @@ class TestModule < Test::Unit::TestCase assert_in_out_err([], src, %w(Object :ok), []) end - module A - B = 42 - end - def test_constant_lookup_in_method_defined_by_class_eval - A.class_eval do - def self.f - B + src = <<-INPUT + class A + B = 42 end - end - assert_raise(NameError) do - A.f - 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_toplevel_class_eval + src = <<-INPUT + module X + A = 123 + end + begin + X.class_eval { A } + rescue NameError => e + puts e + end + INPUT + assert_in_out_err([], src, ["uninitialized constant A"], []) end end diff --git a/vm_insnhelper.c b/vm_insnhelper.c index 00a21e3669..508ad8584e 100644 --- a/vm_insnhelper.c +++ b/vm_insnhelper.c @@ -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)) { |