mirror of
https://github.com/ruby/ruby.git
synced 2025-09-21 03:24:00 +02:00
Avoid top-level search for nested constant reference from nil in defined?
Fixes [Bug #16332] Constant access was changed to no longer allow top-level constant access through `nil`, but `defined?` wasn't changed at the same time to stay consistent. Use a separate defined type to distinguish between a constant referenced from the current lexical scope and one referenced from another namespace.
This commit is contained in:
parent
a5b6d7bca8
commit
ac112f2b5d
Notes:
git
2019-11-13 15:37:26 +09:00
6 changed files with 28 additions and 11 deletions
|
@ -50,8 +50,13 @@ class TestConst < Test::Unit::TestCase
|
|||
|
||||
def test_const_access_from_nil
|
||||
assert_raise(TypeError) { eval("nil::Object") }
|
||||
assert_nil eval("defined?(nil::Object)")
|
||||
|
||||
assert_raise(TypeError) { eval("c = nil; c::Object") }
|
||||
assert_nil eval("c = nil; defined?(c::Object)")
|
||||
|
||||
assert_raise(TypeError) { eval("sc = Class.new; sc::C = nil; sc::C::Object") }
|
||||
assert_nil eval("sc = Class.new; sc::C = nil; defined?(sc::C::Object)")
|
||||
end
|
||||
|
||||
def test_redefinition
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue