Actions
Bug #15758
closedObject.const_defined?(name) falsely returns true on classes that are not defined
Description
in short https://i.imgur.com/qvIIBuu.png
Object.const_defined?('Baz::Bar') -> true
yet Baz::Bar -> class not found!
test to run, all ok on ruby 2.6.0, bug in 2.6.2
class Foo
end
class Bar
end
class Baz
class Foo
end
end
###
def report klass
name = "Object.const_defined?('%s')" % klass
exists = Object.const_defined?(klass)
instance = eval klass rescue nil
check = (exists && instance) || (!exists && !instance)? 'ok' : 'ERROR!'
puts [
name.ljust(35),
exists.to_s.ljust(5),
(instance ? instance.to_s : 'nil').ljust(8),
check
].join(' -> ')
end
report 'Foo'
report 'Bar'
report 'Baz'
report 'Naat'
report 'Baz::Foo'
report 'Baz::Bar'
report 'Baz::Naat'
puts '---'
report 'Baz::Foo::Bar::Baz::Foo' # true in 2.6.2 :)
running produces output
Object.const_defined?('Foo') -> true -> Foo -> ok
Object.const_defined?('Bar') -> true -> Bar -> ok
Object.const_defined?('Baz') -> true -> Baz -> ok
Object.const_defined?('Naat') -> false -> nil -> ok
Object.const_defined?('Baz::Foo') -> true -> Baz::Foo -> ok
Object.const_defined?('Baz::Bar') -> true -> nil -> ERROR!
Object.const_defined?('Baz::Naat') -> false -> nil -> ok
---
Object.const_defined?('Baz::Foo::Bar::Baz::Foo') -> true -> nil -> ERROR!
Files
Actions
Like0
Like0Like0Like0Like0Like0Like0Like0