diff options
author | shugo <shugo@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2011-03-30 05:38:50 +0000 |
---|---|---|
committer | shugo <shugo@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2011-03-30 05:38:50 +0000 |
commit | 3b20c2188046d33a0d3b2c2f711193dd5e02a19c (patch) | |
tree | 53e2022077e5829f34a175e913025657f8dd3d62 | |
parent | 089462f592b630110827fea6624f1890411627e0 (diff) |
* 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]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@31215 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r-- | ChangeLog | 6 | ||||
-rw-r--r-- | test/ruby/test_defined.rb | 33 | ||||
-rw-r--r-- | test/ruby/test_module.rb | 16 | ||||
-rw-r--r-- | vm_insnhelper.h | 3 |
4 files changed, 44 insertions, 14 deletions
@@ -1,3 +1,9 @@ +Wed Mar 30 14:35:15 2011 Shugo Maeda <shugo@ruby-lang.org> + + * 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@fsij.org> * ext/stringio/stringio.c: parenthesize macro arguments. diff --git a/test/ruby/test_defined.rb b/test/ruby/test_defined.rb index de64ac46f8..bae85c9265 100644 --- a/test/ruby/test_defined.rb +++ b/test/ruby/test_defined.rb @@ -86,34 +86,39 @@ class TestDefined < Test::Unit::TestCase 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 diff --git a/test/ruby/test_module.rb b/test/ruby/test_module.rb index ce6e8a66bb..3373594fe3 100644 --- a/test/ruby/test_module.rb +++ b/test/ruby/test_module.rb @@ -1000,4 +1000,20 @@ class TestModule < Test::Unit::TestCase 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 diff --git a/vm_insnhelper.h b/vm_insnhelper.h index 979c3427bc..31ef216027 100644 --- a/vm_insnhelper.h +++ b/vm_insnhelper.h @@ -154,6 +154,9 @@ extern VALUE ruby_vm_const_missing_count; (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 { \ |