Project

General

Profile

Bug #17182

Refinements behavior is broken

Added by osyo (manga osyo) 2 months ago. Updated 2 months ago.

Status:
Closed
Priority:
Normal
Target version:
-
ruby -v:
ruby 3.0.0dev (2020-09-13T03:35:37Z master d7b279e79f) [x86_64-linux]
[ruby-core:100070]

Description

Calling the methods defined by Refinements via super from a singleton method breaks the behavior.

class X
  def hoge
    ["X#hoge"]
  end
end

using Module.new {
  refine X do
    def hoge
      ["refine #hoge"] + super
    end
  end
}

x = X.new

def x.hoge
  ["x.hoge"] + super
end

# Refinements method is not called
p x.hoge
# 2.7.1 => ["x.hoge", "refine #hoge", "X#hoge"]  OK: Expected behavior
# 3.0.0 => ["x.hoge", "X#hoge"]                  NG: Behavior is broken.

# Method#super_method refers to a Refinements method
p x.method(:hoge).super_method.call
# 2.7.1 => ["refine #hoge", "X#hoge"]
# 3.0.0 => ["refine #hoge", "X#hoge"]

This is broken by a fix for [Bug #17007].
commit: https://github.com/ruby/ruby/commit/eeef16e190cdabc2ba474622720f8e3df7bac43b

Is this the intended change?

Updated by jeremyevans0 (Jeremy Evans) 2 months ago

  • Assignee set to shugo (Shugo Maeda)
  • Status changed from Open to Assigned

This is discussed in https://bugs.ruby-lang.org/issues/17007#note-4. I'm not sure whether the previous behavior is spec or just an implementation detail. We could revert eeef16e190cdabc2ba474622720f8e3df7bac43b, but then we end up with a SystemStackError in other cases. shugo (Shugo Maeda), do you know how we should handle this case?

Updated by jeremyevans0 (Jeremy Evans) 2 months ago

After some more thought, I think it's better to revert my fix and reopen #17007. Here's a PR for that, I plan on merging it after it passes CI: https://github.com/ruby/ruby/pull/3564.

#3

Updated by jeremyevans (Jeremy Evans) 2 months ago

  • Status changed from Assigned to Closed

Applied in changeset git|179384a66862d5ef7413b6f4850b97d0becf4ec9.


Revert "Prevent SystemStackError when calling super in module with activated refinement"

This reverts commit eeef16e190cdabc2ba474622720f8e3df7bac43b.

This also reverts the spec change.

Preventing the SystemStackError would be nice, but there is valid
code that the fix breaks, and it is probably more common than cases
that cause the SystemStackError.

Fixes [Bug #17182]

Also available in: Atom PDF