Issue #15875 has been updated by nagachika (Tomoyuki Chikanaga).
Backport changed from 2.4: DONTNEED, 2.5: DONTNEED, 2.6: REQUIRED to 2.4: DONTNEED, 2.5: DONTNEED, 2.6: DONE
ruby_2_6 r67830 merged revision(s) e1b592b508c72a56ae012869d97fe1580ff87246,d10451f3fd51f577e704db770de48d05044eb45c.
----------------------------------------
Bug #15875: const_defined? behavior inconsistency in 2.6.x series
https://bugs.ruby-lang.org/issues/15875#change-83037
* Author: matsuda (Akira Matsuda)
* Status: Closed
* Priority: Normal
* Assignee:
* Target version:
* ruby -v: 2.6.1, 2.6.2, 2.6.3
* Backport: 2.4: DONTNEED, 2.5: DONTNEED, 2.6: DONE
----------------------------------------
`Module#const_defined?` returns true for unreachable nested fully qualified module name.
Here are the results of `const_defined?` for each ruby version on my machine.
```
% ruby -e "module A; end; B = 1; p Object.const_defined?('A::B')"
[1.9.3-p551, 2.0.0-p648]
-e:1:in `const_defined?': wrong constant name A::B (NameError)
from -e:1:in `<main>'
[2.1.10, 2.2.10, 2.3.8, 2.4.6, 2.5.5, 2.6.0]
false
[2.6.1, 2.6.2, 2.6.3]
true
[2.7.0-dev (2019-05-25 trunk 559dca509d)]
false
```
For (2.6.1...2.6.3), it fails to reference the constant even though `const_defined?` returns true. So IMO this should be `const_defined?`'s bug.
```
% ruby -e "module A; end; B = 1; p Object.const_defined?('A::B') && A::B"
-e:1:in `<main>': uninitialized constant A::B (NameError)
```
--
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.