[ruby-core:96160] [Ruby master Bug#15780] Module#const_defined?(String) executes autoloads

[email protected]
Newsgroups gmane.comp.lang.ruby.core
Message-ID <redmine.journal-83038.20191209122543.b89180925079976c@ruby-lang.org>
Issue #15780 has been updated by nagachika (Tomoyuki Chikanaga).

Backport changed from 2.4: REQUIRED, 2.5: REQUIRED, 2.6: REQUIRED to 2.4: REQUIRED, 2.5: REQUIRED, 2.6: DONE

ruby_2_6 r67831 merged revision(s) 7d805e67f3275aef066d77aa9c32bef715c362ed.

----------------------------------------
Bug #15780: Module#const_defined?(String) executes autoloads
https://bugs.ruby-lang.org/issues/15780#change-83038

* Author: fxn (Xavier Noria)
* Status: Closed
* Priority: Normal
* Assignee: 
* Target version: 
* ruby -v: ruby 2.6.1p33 (2019-01-30 revision 66950) [x86_64-darwin18]
* Backport: 2.4: REQUIRED, 2.5: REQUIRED, 2.6: DONE
----------------------------------------
The documentation of `Module#const_defined?` says that autoloads are not executed:

> [...] if the constant is not present but there is an autoload for it, true is returned directly without autoloading.

While this seems to work as documented for symbols, constant names passed as strings trigger the autoload:

```
$ cat x.rb
p X = 1

$ cat foo.rb
Object.autoload("X", "x")
p Object.const_defined?("X")

$ ruby -I. foo.rb
1
true
```



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

Unsubscribe: <mailto:[email protected]?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-core>
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.