ruby-changes:19176
From: shugo <ko1@a...>
Date: Wed, 30 Mar 2011 14:38:57 +0900 (JST)
Subject: [ruby-changes:19176] Ruby:r31215 (trunk): * vm_insnhelper.h (COPY_CREF): should copy
shugo 2011-03-30 14:38:50 +0900 (Wed, 30 Mar 2011) New Revision: 31215 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=31215 Log: * vm_insnhelper.h (COPY_CREF): should copy the NODE_FL_CREF_PUSHED_BY_EVAL flag to hide constants from methods defined by class_eval. [ruby-dev:43365] Modified files: trunk/ChangeLog trunk/test/ruby/test_defined.rb trunk/test/ruby/test_module.rb trunk/vm_insnhelper.h Index: ChangeLog =================================================================== --- ChangeLog (revision 31214) +++ ChangeLog (revision 31215) @@ -1,3 +1,9 @@ +Wed Mar 30 14:35:15 2011 Shugo Maeda <shugo@r...> + + * vm_insnhelper.h (COPY_CREF): should copy + the NODE_FL_CREF_PUSHED_BY_EVAL flag to hide constants from + methods defined by class_eval. [ruby-dev:43365] + Wed Mar 30 00:24:53 2011 Tanaka Akira <akr@f...> * ext/stringio/stringio.c: parenthesize macro arguments. Index: vm_insnhelper.h =================================================================== --- vm_insnhelper.h (revision 31214) +++ vm_insnhelper.h (revision 31215) @@ -154,6 +154,9 @@ (c1)->nd_clss = __tmp_c2->nd_clss; \ (c1)->nd_visi = __tmp_c2->nd_visi;\ (c1)->nd_next = __tmp_c2->nd_next; \ + if (__tmp_c2->flags & NODE_FL_CREF_PUSHED_BY_EVAL) { \ + (c1)->flags |= NODE_FL_CREF_PUSHED_BY_EVAL; \ + } \ } while (0) #define CALL_METHOD(num, blockptr, flag, id, me, recv) do { \ Index: test/ruby/test_module.rb =================================================================== --- test/ruby/test_module.rb (revision 31214) +++ test/ruby/test_module.rb (revision 31215) @@ -1000,4 +1000,20 @@ INPUT 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 + end + end + + assert_raise(NameError) do + A.f + end + end end Index: test/ruby/test_defined.rb =================================================================== --- test/ruby/test_defined.rb (revision 31214) +++ test/ruby/test_defined.rb (revision 31215) @@ -86,34 +86,39 @@ assert_equal nil, defined?($2) end + class TestAutoloadedSuperclass + autoload :A, "a" + end + + class TestAutoloadedSubclass < TestAutoloadedSuperclass + def a? + defined?(A) + end + end + def test_autoloaded_subclass bug = "[ruby-core:35509]" - klass = Class.new do - autoload(:A, "a") - end - x = klass.new + x = TestAutoloadedSuperclass.new class << x def a?; defined?(A); end end assert_equal("constant", x.a?, bug) - klass = Class.new(klass) do - def a?; defined?(A); end + assert_equal("constant", TestAutoloadedSubclass.new.a?, bug) + end + + class TestAutoloadedNoload + autoload :A, "a" + def a? + defined?(A) end - assert_equal("constant", klass.new.a?, bug) end def test_autoloaded_noload loaded = $".dup $".clear - klass = Class.new do - autoload(:A, "a") - def a? - defined?(A) - end - end - x = klass.new + x = TestAutoloadedNoload.new assert_equal("constant", x.a?) assert_equal([], $") ensure -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/