mirror of
https://github.com/ruby/ruby.git
synced 2025-09-18 10:03:59 +02:00
* 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
This commit is contained in:
parent
089462f592
commit
3b20c21880
4 changed files with 44 additions and 14 deletions
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue