From 7487298584145058f2340dc7a6e4da8d21fe5248 Mon Sep 17 00:00:00 2001 From: shugo Date: Thu, 31 Mar 2011 09:07:42 +0000 Subject: [PATCH] * vm_insnhelper.c (vm_get_ev_const): should ignore crefs with the NODE_FL_CREF_PUSHED_BY_EVAL flag. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@31222 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ChangeLog | 5 +++++ test/ruby/test_module.rb | 19 +++++++++++++++++++ vm_insnhelper.c | 7 ++++++- 3 files changed, 30 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index e38f4f98c6..57c6c8ba3b 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +Thu Mar 31 18:06:12 2011 Shugo Maeda + + * vm_insnhelper.c (vm_get_ev_const): should ignore crefs with + the NODE_FL_CREF_PUSHED_BY_EVAL flag. + Thu Mar 31 16:49:56 2011 Shugo Maeda * vm_insnhelper.c (vm_get_ev_const): search root cref properly. diff --git a/test/ruby/test_module.rb b/test/ruby/test_module.rb index 6d28616d86..10b2708804 100644 --- a/test/ruby/test_module.rb +++ b/test/ruby/test_module.rb @@ -1049,4 +1049,23 @@ class TestModule < Test::Unit::TestCase INPUT assert_in_out_err([], src, ["uninitialized constant A"], []) end + + def test_constant_lookup_in_module_in_class_eval + src = <<-INPUT + class A + B = 42 + end + + A.class_eval do + module C + begin + B + rescue NameError + puts "NameError" + end + end + end + INPUT + assert_in_out_err([], src, ["NameError"], []) + end end diff --git a/vm_insnhelper.c b/vm_insnhelper.c index 508ad8584e..3398b958ab 100644 --- a/vm_insnhelper.c +++ b/vm_insnhelper.c @@ -1164,7 +1164,12 @@ vm_get_ev_const(rb_thread_t *th, const rb_iseq_t *iseq, } cref = root_cref; while (cref && cref->nd_next) { - klass = cref->nd_clss; + if (cref->flags & NODE_FL_CREF_PUSHED_BY_EVAL) { + klass = Qnil; + } + else { + klass = cref->nd_clss; + } cref = cref->nd_next; if (!NIL_P(klass)) {