From: nobu@ruby-lang.org
To: ruby-core@ruby-lang.org
Subject: [ruby-core:98624] [Ruby master Bug#16931] `defined?` against a protected method call on an inherited instance returns wrong `nil`
Date: Tue, 02 Jun 2020 10:01:21 +0000 (UTC) [thread overview]
Message-ID: <redmine.issue-16931.20200602100120.4@ruby-lang.org> (raw)
In-Reply-To: redmine.issue-16931.20200602100120.4@ruby-lang.org
Issue #16931 has been reported by nobu (Nobuyoshi Nakada).
----------------------------------------
Bug #16931: `defined?` against a protected method call on an inherited instance returns wrong `nil`
https://bugs.ruby-lang.org/issues/16931
* Author: nobu (Nobuyoshi Nakada)
* Status: Open
* Priority: Normal
* ruby -v: 2.8.0dev (2020-06-02T08:21:03Z master 56ca006784)
* Backport: 2.5: REQUIRED, 2.6: REQUIRED, 2.7: REQUIRED
----------------------------------------
The following code shows `:callable` first, but `nil` next, since 1.9.
If the method is callable, `defined?` expression has to return truthy value.
``` ruby
class A
def foo
:callable
end
protected :foo
def t(x)
x.foo
end
def q(x)
defined?(x.foo)
end
end
class B<A
end
a = A.new
b = B.new
p a.t(b) #=> :callable
p a.q(b) #=> nil
```
--
https://bugs.ruby-lang.org/
next parent reply other threads:[~2020-06-02 10:01 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-06-02 10:01 nobu [this message]
2020-08-01 8:34 ` [ruby-core:99430] [Ruby master Bug#16931] `defined?` against a protected method call on an inherited instance returns wrong `nil` nagachika00
2020-08-01 8:34 ` [ruby-core:99431] " nagachika00
2021-04-04 23:03 ` [ruby-core:103218] " usa
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-list from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.ruby-lang.org/en/community/mailing-lists/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=redmine.issue-16931.20200602100120.4@ruby-lang.org \
--to=ruby-core@ruby-lang.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).