Project

General

Profile

Actions

Bug #21446

closed

StackOverflow when changing visibility in reopened refinement

Bug #21446: StackOverflow when changing visibility in reopened refinement

Added by luke-gru (Luke Gruber) 6 months ago. Updated about 10 hours ago.

Status:
Closed
Assignee:
-
Target version:
-
[ruby-core:122558]

Description

class A
  def a
    :a
  end
end
class B < A
end

module R
  refine B do
    private :a
  end
end
module R
  refine B do
    public :a
  end
end
using R
B.new.a # StackOverflow

I would expect it to change the visibility, not to overflow the stack.

Updated by nobu (Nobuyoshi Nakada) 6 months ago Actions #1 [ruby-core:122560]

It does not seem to need to reopen the refinement.

Reproduces just by changing visibility twice.

module R
  refine B do
    private :a
    public :a
  end
end

Updated by nobu (Nobuyoshi Nakada) 6 months ago Actions #2

  • Backport changed from 3.2: UNKNOWN, 3.3: UNKNOWN, 3.4: UNKNOWN to 3.2: REQUIRED, 3.3: REQUIRED, 3.4: REQUIRED

Updated by jeremyevans0 (Jeremy Evans) 2 months ago Actions #3 [ruby-core:123468]

I found that you don't even need to change the visibility twice. This issue affects all refinement visibility change methods where the method whose visibility is changed by the refinement is in an ancestor of the refined class. Here's a simplified example:

class A
  private def a
    :a
  end
end
class B < A
end

module R
  refine B do
    public :a
  end
end
using R
p B.new.a

I've submitted a pull request that handles this case: https://github.com/ruby/ruby/pull/14817

Updated by jeremyevans (Jeremy Evans) about 10 hours ago Actions #4

  • Status changed from Open to Closed

Applied in changeset git|1e7cf7b2bc1f9b356b2e980e1e18548618da6363.


Fix refinement modification of method visibility in superclass

Previously, this didn't work correctly, resulting in a
SystemStackError. This fixes the issue by finding the related
superclass method entry, and updating the orig_me in the
refinement method to point to the superclass method.

Fixes [Bug #21446]

Actions

Also available in: PDF Atom