ruby-core@ruby-lang.org archive (unofficial mirror)
 help / color / mirror / Atom feed
* [ruby-core:95746] [Ruby master Bug#16332] `defined?` constant access on `nil` is inconsistent with normal constant access
       [not found] <redmine.issue-16332.20191107164207@ruby-lang.org>
@ 2019-11-07 16:42 ` dylan.smith
  0 siblings, 0 replies; only message in thread
From: dylan.smith @ 2019-11-07 16:42 UTC (permalink / raw)
  To: ruby-core

Issue #16332 has been reported by dylants (Dylan Thacker-Smith).

----------------------------------------
Bug #16332: `defined?` constant access on `nil` is inconsistent with normal constant access
https://bugs.ruby-lang.org/issues/16332

* Author: dylants (Dylan Thacker-Smith)
* Status: Open
* Priority: Normal
* Assignee: 
* Target version: 
* ruby -v: ruby 2.7.0dev (2019-11-07T14:33:45Z master d62abc47c8) [x86_64-darwin18]
* Backport: 2.5: UNKNOWN, 2.6: UNKNOWN
----------------------------------------
The fix for https://bugs.ruby-lang.org/issues/11718 to disallow constant access through `nil` (e.g. `nil::CONSTANT`) didn't make a corresponding change for `defined?`.

This inconsistency can be seen with the example `nil::Object`, which will raise `TypeError`, even though `defined?(nil::Object)` returns `"constant"`.  I believe that `defined?(nil::Object)` should behave the same way as checking if a constant is defined on any other non-namespace object (e.g. `defined?(1::Object)`), which currently returns `nil`.

I've opened pull request https://github.com/ruby/ruby/pull/2657 with a fix for this issue.



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

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2019-11-07 16:42 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <redmine.issue-16332.20191107164207@ruby-lang.org>
2019-11-07 16:42 ` [ruby-core:95746] [Ruby master Bug#16332] `defined?` constant access on `nil` is inconsistent with normal constant access dylan.smith

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).