From: "matz (Yukihiro Matsumoto)" <noreply@ruby-lang.org>
To: ruby-core@ruby-lang.org
Subject: [ruby-core:108765] [Ruby master Bug#18435] Calling `protected` on ancestor method changes result of `instance_methods(false)`
Date: Fri, 03 Jun 2022 06:54:36 +0000 (UTC) [thread overview]
Message-ID: <redmine.journal-97830.20220603065435.39299@ruby-lang.org> (raw)
In-Reply-To: redmine.issue-18435.20211226142230.39299@ruby-lang.org
Issue #18435 has been updated by matz (Yukihiro Matsumoto).
Status changed from Closed to Open
I thought it was OK to accept this behavior, but it caused issues like #18729 and #18751. At the time of the decision, I haven't noticed those corner cases. Although it has already been shipped with 3.1, I proposed to revert this change. I estimate the impact of reverting incompatibility is minimal.
Instead of changing old behavior, the documentation of `instance_methods(false)` should be updated to explain why `method1` is included in the above example (visibility changes or making aliases are considered as *definition* by `instance_methods`).
Matz.
----------------------------------------
Bug #18435: Calling `protected` on ancestor method changes result of `instance_methods(false)`
https://bugs.ruby-lang.org/issues/18435#change-97830
* Author: ufuk (Ufuk Kayserilioglu)
* Status: Open
* Priority: Normal
* ruby -v: ruby 2.7.5p203 (2021-11-24 revision f69aeb8314) [x86_64-darwin20]
* Backport: 2.6: UNKNOWN, 2.7: UNKNOWN, 3.0: UNKNOWN, 3.1: UNKNOWN
----------------------------------------
As documented `instance_methods(false)` works as follows:
```ruby
module A
def method1() end
end
class B
include A
def method2() end
end
p B.instance_methods(false) #=> [:method2]
```
However, calling `protected` on the method defined by `A`, unexpectedly changes the result of `instance_methods(false)` on `B`, even though the owner of the method is still `A`:
```ruby
module A
def method1() end
end
class B
include A
protected :method1
def method2() end
end
p B.instance_methods(false) #=> [:method1, :method2]
p B.instance_method(:method1).owner #=> A
```
In contrast, calling `private` or `public` on the same method does not cause any changes on the result of `B.instance_methods(false)`.
This feels like a bug in the implementation of `instance_methods(false)`, but, if it is by design, it should at least be documented on `Module#instance_methods`.
This reproduction script gives the same output all the way from Ruby 2.0 up to Ruby-HEAD:
https://wandbox.org/permlink/LqbXMBTYxURRZmDz
--
https://bugs.ruby-lang.org/
next prev parent reply other threads:[~2022-06-03 6:54 UTC|newest]
Thread overview: 23+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-12-26 14:22 [ruby-core:106828] [Ruby master Bug#18435] Calling `protected` on ancestor method changes result of `instance_methods(false)` ufuk (Ufuk Kayserilioglu)
2021-12-26 21:09 ` [ruby-core:106829] " jeremyevans0 (Jeremy Evans)
2021-12-27 12:34 ` [ruby-core:106835] " ufuk (Ufuk Kayserilioglu)
2021-12-27 16:23 ` [ruby-core:106839] " jeremyevans0 (Jeremy Evans)
2021-12-27 19:28 ` [ruby-core:106842] " jeremyevans0 (Jeremy Evans)
2022-01-05 1:23 ` [ruby-core:106968] " alanwu (Alan Wu)
2022-01-07 17:46 ` [ruby-core:107003] " Eregon (Benoit Daloze)
2022-01-14 0:56 ` [ruby-core:107107] " jeremyevans0 (Jeremy Evans)
2022-06-03 6:54 ` matz (Yukihiro Matsumoto) [this message]
2022-06-09 10:23 ` [ruby-core:108833] " Eregon (Benoit Daloze)
2022-08-10 20:32 ` [ruby-core:109471] " jeremyevans0 (Jeremy Evans)
2022-08-13 3:27 ` [ruby-core:109477] " nagachika (Tomoyuki Chikanaga)
2022-08-13 3:31 ` [ruby-core:109478] " jeremyevans0 (Jeremy Evans)
2022-08-15 10:56 ` [ruby-core:109479] " Eregon (Benoit Daloze)
2022-08-15 11:11 ` [ruby-core:109483] " Eregon (Benoit Daloze)
2022-08-15 13:08 ` [ruby-core:109484] " Eregon (Benoit Daloze)
2022-08-18 9:24 ` [ruby-core:109538] " Eregon (Benoit Daloze)
2022-08-18 9:27 ` [ruby-core:109539] " Eregon (Benoit Daloze)
2022-08-20 12:30 ` [ruby-core:109593] " Eregon (Benoit Daloze)
2022-08-20 12:38 ` [ruby-core:109595] " Eregon (Benoit Daloze)
2022-09-03 6:06 ` [ruby-core:109827] " nagachika (Tomoyuki Chikanaga)
2022-09-29 13:52 ` [ruby-core:110148] " Eregon (Benoit Daloze)
2022-10-01 6:35 ` [ruby-core:110157] " nagachika (Tomoyuki Chikanaga)
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.journal-97830.20220603065435.39299@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).