[ruby-core:92202] [Ruby trunk Bug#15758] Object.const_defined?(name) falsely returns true on classes that are not defined

From: rejotl@...
Date: 2019-04-08 11:30:34 UTC
List: ruby-core #92202
Issue #15758 has been reported by dux (Dino Reic).

----------------------------------------
Bug #15758: Object.const_defined?(name) falsely returns true on classes that are not defined
https://bugs.ruby-lang.org/issues/15758

* Author: dux (Dino Reic)
* Status: Open
* Priority: Normal
* Assignee: 
* Target version: 
* ruby -v: 2.6.2
* Backport: 2.4: UNKNOWN, 2.5: UNKNOWN, 2.6: UNKNOWN
----------------------------------------
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'


---Files--------------------------------
bug.rb (581 Bytes)


-- 
https://bugs.ruby-lang.org/

Unsubscribe: <mailto:[email protected]?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-core>

In This Thread

Prev Next