From 5069c5f5214ce68df8b3954321ad9114c5368dc3 Mon Sep 17 00:00:00 2001 From: Jeremy Evans Date: Sat, 12 Oct 2019 00:01:37 -0700 Subject: Honor refinements for modules that prepend other modules This previously did not work, and the reason it did not work is that: 1) Refining a module or class that prepends other modules places the refinements in the class itself and not the origin iclass. 2) Inclusion of a module that prepends other modules skips the module itself, including only iclasses for the prepended modules and the origin iclass. Those two behaviors combined meant that the method table for the refined methods for the included module never ends up in the method lookup chain for the class including the module. Fix this by not skipping the module itself when the module is included. This requires some code rearranging in rb_include_class_new to make sure the correct method tables and origin settings are used for the created iclass. As origin iclasses shouldn't be exposed to Ruby, this also requires skipping modules that have origin iclasses in Module#ancestors (classes that have origin iclasses were already skipped). Fixes [Bug #16242] --- test/ruby/test_refinement.rb | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) (limited to 'test') diff --git a/test/ruby/test_refinement.rb b/test/ruby/test_refinement.rb index 9d8bb92648..618175f931 100644 --- a/test/ruby/test_refinement.rb +++ b/test/ruby/test_refinement.rb @@ -2322,6 +2322,34 @@ class TestRefinement < Test::Unit::TestCase assert_equal(:ok, RefineInUsing.test) end + class Bug16242 + module OtherM + end + + module M + prepend OtherM + + refine M do + def refine_method + "refine_method" + end + end + using M + + def hoge + refine_method + end + end + + class X + include M + end + end + + def test_refine_prepended_module + assert_equal("refine_method", Bug16242::X.new.hoge) + end + private def eval_using(mod, s) -- cgit v1.2.3