Project

General

Profile

Actions

Bug #22555

open

Missing CC invalidation when changing visibility using Method object

Bug #22555: Missing CC invalidation when changing visibility using Method object

Added by luke-gru (Luke Gruber) about 8 hours ago. Updated about 8 hours ago.

Status:
Open
Target version:
[ruby-core:127532]

Description

A Method object that is used to define another method with the same name but with a different visibility mutates the def of the original method. This is fine,
however it doesn't clear the CCs of the old method.

class Warm; def foo = 1; end
class Cold; def foo = 1; end

def call_warm(o) = o.foo

warm = Warm.new
cold = Cold.new
2.times { call_warm(warm) }

[Warm, Cold].each do |k|
  k.class_eval do
    private
    define_method(:foo, instance_method(:foo))
  end
end

results = {
  warm_private_method_defined: Warm.private_method_defined?(:foo),
  warm_cached_site:            (call_warm(warm) rescue $!.class),
  warm_fresh_site:             (warm.foo rescue $!.class),
  cold_site:                   (cold.foo rescue $!.class),
}
results.each { |k, v| puts "#{k}: #{v.inspect}" }

stale = results.values_at(:warm_cached_site, :warm_fresh_site, :cold_site).reject { it == NoMethodError }
if stale.empty?
  puts "ok"
else
  puts "BUG: private method still callable through a stale cache"
  exit 1
Actions

Also available in: PDF Atom