summaryrefslogtreecommitdiff
path: root/test/ruby
diff options
context:
space:
mode:
authorShugo Maeda <shugo@ruby-lang.org>2024-02-27 14:19:15 +0900
committerShugo Maeda <shugo.maeda@gmail.com>2024-02-27 14:51:04 +0900
commitd50f9ca2dd416d92152cd958b5f39496088481b0 (patch)
tree7dd8160371543bda6de376c7ff45fc56e28b9202 /test/ruby
parent3a04ea2d0379dd8c6623c2d5563e6b4e23986fae (diff)
[Bug #20302] Multiple refinements cannot be applied to the same module
In the following code, the iclass tree of refinements in cref should be <iclass of Kernel@M2> -> <iclass of Kernel@M1> -> Kernel. However, the iclass tree was broken because of code for included modules of refinements in rb_using_refinement(). Refinement#include is now removed, so this commit removes such unnecessary code. ```ruby module M1 refine(Kernel) do def f1 = :f1 end end module M2 refine(Kernel) do def f2 = :f2 end end class Foo using M1 using M2 def test p f2 #=> :f2 p f1 # expected => :f1 # actual => undefined local variable or method 'f1' for an instance of Foo end end Foo.new.test ```
Diffstat (limited to 'test/ruby')
-rw-r--r--test/ruby/test_refinement.rb29
1 files changed, 29 insertions, 0 deletions
diff --git a/test/ruby/test_refinement.rb b/test/ruby/test_refinement.rb
index 826616eb09..cb55627e2c 100644
--- a/test/ruby/test_refinement.rb
+++ b/test/ruby/test_refinement.rb
@@ -2672,6 +2672,35 @@ class TestRefinement < Test::Unit::TestCase
assert_equal(:v2, obj.cached_foo_callsite)
end
+ # [Bug #20302]
+ def test_multiple_refinements_for_same_module
+ assert_in_out_err([], <<-INPUT, %w(:f2 :f1), [])
+ module M1
+ refine(Kernel) do
+ def f1 = :f1
+ end
+ end
+
+ module M2
+ refine(Kernel) do
+ def f2 = :f2
+ end
+ end
+
+ class Foo
+ using M1
+ using M2
+
+ def test
+ p f2
+ p f1
+ end
+ end
+
+ Foo.new.test
+ INPUT
+ end
+
private
def eval_using(mod, s)