From: "luke-gru (Luke Gruber) via ruby-core" Date: 2026-11-16T21:33:19+00:00 Subject: [ruby-core:127533] [Ruby Bug#22555] Missing CC invalidation when changing visibility on Method object Issue #22555 has been updated by luke-gru (Luke Gruber). PR [here](https://github.com/ruby/ruby/pull/19926) ---------------------------------------- Bug #22555: Missing CC invalidation when changing visibility on Method object https://bugs.ruby-lang.org/issues/22555#change-120003 * Author: luke-gru (Luke Gruber) * Status: Open * Assignee: luke-gru (Luke Gruber) * Target version: 4.1 * Backport: 3.3: UNKNOWN, 3.4: UNKNOWN, 4.0: UNKNOWN ---------------------------------------- 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. ```ruby 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 ``` -- https://bugs.ruby-lang.org/ ______________________________________________ ruby-core mailing list -- ruby-core@ml.ruby-lang.org To unsubscribe send an email to ruby-core-leave@ml.ruby-lang.org ruby-core info -- https://ml.ruby-lang.org/mailman3/lists/ruby-core.ml.ruby-lang.org/