From: merch-redmine@... Date: 2020-06-09T20:28:34+00:00 Subject: [ruby-core:98693] [Ruby master Bug#16942] instance_method causes an infinite loop with prepend, include and private Issue #16942 has been updated by jeremyevans0 (Jeremy Evans). This issue first occurred in Ruby 2.3. The problematic code is the `goto again` loop in `mnew_internal`. You can end up with a situation where `klass` is the same or an ancestor of `RCLASS_SUPER(me->owner)`, so `klass` never changes. This is possible to work around by detecting this case and using `RCLASS_SUPER(klass)` instead of `RCLASS_SUPER(me->owner)` in this case. However, this approach is O(m*n), where m is the number of ZSUPER methods and n is the length of the super chain of `RCLASS_SUPER(me->owner)`. Unfortunately, I don't have enough knowledge of the internals to determine if there is a more efficient solution, or if the work around will cause other problems. I submitted a pull request for the work around: https://github.com/ruby/ruby/pull/3201 ---------------------------------------- Bug #16942: instance_method causes an infinite loop with prepend, include and private https://bugs.ruby-lang.org/issues/16942#change-86039 * Author: pocke (Masataka Kuwabara) * Status: Open * Priority: Normal * ruby -v: ruby 2.8.0dev (2020-06-09T13:51:54Z master 7f3efee102) [x86_64-linux] * Backport: 2.5: UNKNOWN, 2.6: UNKNOWN, 2.7: UNKNOWN ---------------------------------------- `instance_method` causes an infinite loop with the following code. ```ruby module M def x end end module M2 include M private :x end ::Object.prepend(M2) # infinite loop p Object.instance_method(:x) ``` I've confirmed it on the master branch. The commit is 7f3efee102. But `instance_method` works correctly with Ruby 2.7.1. -- https://bugs.ruby-lang.org/ Unsubscribe: