ruby-core@ruby-lang.org archive (unofficial mirror)
 help / color / mirror / Atom feed
From: "Eregon (Benoit Daloze)" <noreply@ruby-lang.org>
To: ruby-core@ruby-lang.org
Subject: [ruby-core:109479] [Ruby master Bug#18435] Calling `protected` on ancestor method changes result of `instance_methods(false)`
Date: Mon, 15 Aug 2022 10:56:00 +0000 (UTC)	[thread overview]
Message-ID: <redmine.journal-98647.20220815105559.39299@ruby-lang.org> (raw)
In-Reply-To: redmine.issue-18435.20211226142230.39299@ruby-lang.org

Issue #18435 has been updated by Eregon (Benoit Daloze).


protected methods like in this issue are part of the method table, so I think it makes no sense to hide them.
What we need to do is to stop hiding ZSUPER methods: https://bugs.ruby-lang.org/issues/18751#note-12

Ruby implementations which do not use "ZSUPER methods" (i.e., both JRuby and TruffleRuby) already expose such methods in `instance_methods`, as it should be semantically.

I don't think it makes sense to backport this, it's just likely to cause unnecessary incompatibilities and confusion for people updating from 3.1.2 to 3.1.3.

----------------------------------------
Bug #18435: Calling `protected` on ancestor method changes result of `instance_methods(false)`
https://bugs.ruby-lang.org/issues/18435#change-98647

* Author: ufuk (Ufuk Kayserilioglu)
* Status: Closed
* Priority: Normal
* ruby -v: ruby 2.7.5p203 (2021-11-24 revision f69aeb8314) [x86_64-darwin20]
* Backport: 2.6: DONTNEED, 2.7: DONTNEED, 3.0: DONTNEED, 3.1: REQUIRED
----------------------------------------
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/

  parent reply	other threads:[~2022-08-15 10:56 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 ` [ruby-core:108765] " matz (Yukihiro Matsumoto)
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 ` Eregon (Benoit Daloze) [this message]
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-98647.20220815105559.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).