ruby-changes:19182
From: shugo <ko1@a...>
Date: Thu, 31 Mar 2011 16:52:50 +0900 (JST)
Subject: [ruby-changes:19182] Ruby:r31221 (trunk): * vm_insnhelper.c (vm_get_ev_const): search root cref properly.
shugo 2011-03-31 16:52:40 +0900 (Thu, 31 Mar 2011) New Revision: 31221 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=31221 Log: * vm_insnhelper.c (vm_get_ev_const): search root cref properly. [ruby-dev:43365] Modified files: trunk/ChangeLog trunk/bootstraptest/test_eval.rb trunk/test/ruby/test_module.rb trunk/vm_insnhelper.c Index: ChangeLog =================================================================== --- ChangeLog (revision 31220) +++ ChangeLog (revision 31221) @@ -1,3 +1,8 @@ +Thu Mar 31 16:49:56 2011 Shugo Maeda <shugo@r...> + + * vm_insnhelper.c (vm_get_ev_const): search root cref properly. + [ruby-dev:43365] + Thu Mar 31 14:50:25 2011 Shugo Maeda <shugo@r...> * eval.c (rb_mod_s_constants): should ignore crefs with Index: bootstraptest/test_eval.rb =================================================================== --- bootstraptest/test_eval.rb (revision 31220) +++ bootstraptest/test_eval.rb (revision 31221) @@ -137,7 +137,7 @@ } C.new.m } -assert_equal %q{C}, %q{ +assert_equal %q{top}, %q{ Const = :top class C Const = :C Index: vm_insnhelper.c =================================================================== --- vm_insnhelper.c (revision 31220) +++ vm_insnhelper.c (revision 31221) @@ -1155,16 +1155,16 @@ 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)) { Index: test/ruby/test_module.rb =================================================================== --- test/ruby/test_module.rb (revision 31220) +++ test/ruby/test_module.rb (revision 31221) @@ -1006,19 +1006,47 @@ 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 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/