Clear all refined CCs on reopening refinement mod

In cfd7729ce7a31c8b6ec5dd0e99c67b2932de4732 we started using inline
caches for refinements. However, we weren't clearing inline caches when
defined on a reopened refinement module.

Fixes [Bug #20246]
This commit is contained in:
John Hawthorn 2024-02-19 18:53:13 -08:00
parent 4a4e5dd9c9
commit 18ee7c9a10
2 changed files with 18 additions and 0 deletions

View File

@ -1606,18 +1606,35 @@ class TestRefinement < Test::Unit::TestCase
end end
using R using R
def m
C.new.m
end
assert_equal(:foo, C.new.m) assert_equal(:foo, C.new.m)
assert_equal(:foo, m)
module R module R
refine C do refine C do
assert_equal(:foo, C.new.m)
assert_equal(:foo, m)
alias m m alias m m
assert_equal(:foo, C.new.m)
assert_equal(:foo, m)
def m def m
:bar :bar
end end
assert_equal(:bar, C.new.m, "[ruby-core:71423] [Bug #11672]")
assert_equal(:bar, m, "[Bug #20285]")
end end
end end
assert_equal(:bar, C.new.m, "[ruby-core:71423] [Bug #11672]") assert_equal(:bar, C.new.m, "[ruby-core:71423] [Bug #11672]")
assert_equal(:bar, m, "[Bug #20285]")
end; end;
end end

View File

@ -301,6 +301,7 @@ rb_clear_method_cache(VALUE klass_or_module, ID mid)
VALUE refined_class = rb_refinement_module_get_refined_class(module); VALUE refined_class = rb_refinement_module_get_refined_class(module);
rb_clear_method_cache(refined_class, mid); rb_clear_method_cache(refined_class, mid);
rb_class_foreach_subclass(refined_class, clear_iclass_method_cache_by_id_for_refinements, mid); rb_class_foreach_subclass(refined_class, clear_iclass_method_cache_by_id_for_refinements, mid);
rb_clear_all_refinement_method_cache();
} }
rb_class_foreach_subclass(module, clear_iclass_method_cache_by_id, mid); rb_class_foreach_subclass(module, clear_iclass_method_cache_by_id, mid);
} }