ruby-changes:19183
From: shugo <ko1@a...>
Date: Thu, 31 Mar 2011 18:07:53 +0900 (JST)
Subject: [ruby-changes:19183] Ruby:r31222 (trunk): * vm_insnhelper.c (vm_get_ev_const): should ignore crefs with
shugo 2011-03-31 18:07:42 +0900 (Thu, 31 Mar 2011) New Revision: 31222 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=31222 Log: * vm_insnhelper.c (vm_get_ev_const): should ignore crefs with the NODE_FL_CREF_PUSHED_BY_EVAL flag. Modified files: trunk/ChangeLog trunk/test/ruby/test_module.rb trunk/vm_insnhelper.c Index: ChangeLog =================================================================== --- ChangeLog (revision 31221) +++ ChangeLog (revision 31222) @@ -1,3 +1,8 @@ +Thu Mar 31 18:06:12 2011 Shugo Maeda <shugo@r...> + + * 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 <shugo@r...> * vm_insnhelper.c (vm_get_ev_const): search root cref properly. Index: vm_insnhelper.c =================================================================== --- vm_insnhelper.c (revision 31221) +++ vm_insnhelper.c (revision 31222) @@ -1164,7 +1164,12 @@ } 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)) { Index: test/ruby/test_module.rb =================================================================== --- test/ruby/test_module.rb (revision 31221) +++ test/ruby/test_module.rb (revision 31222) @@ -1049,4 +1049,23 @@ 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 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/