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:ruby-core-request / ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-core>