[前][次][番号順一覧][スレッド一覧]

ruby-changes:67198

From: Shugo <ko1@a...>
Date: Fri, 20 Aug 2021 10:44:17 +0900 (JST)
Subject: [ruby-changes:67198] 754adbee91 (master): Module#ancestors should not return superclasses of refinements

https://git.ruby-lang.org/ruby.git/commit/?id=754adbee91

From 754adbee91c2d4a4e84e9271724ca33f630d1916 Mon Sep 17 00:00:00 2001
From: Shugo Maeda <shugo@r...>
Date: Fri, 20 Aug 2021 10:42:01 +0900
Subject: Module#ancestors should not return superclasses of refinements

[ruby-core:86949] [Bug #14744]

Reported by Eregon (Benoit Daloze).  Thanks!
---
 class.c                      |  5 +++++
 test/ruby/test_refinement.rb | 12 ++++++++++++
 2 files changed, 17 insertions(+)

diff --git a/class.c b/class.c
index 41dbcf5..9e5cf54 100644
--- a/class.c
+++ b/class.c
@@ -1347,8 +1347,13 @@ VALUE https://github.com/ruby/ruby/blob/trunk/class.c#L1347
 rb_mod_ancestors(VALUE mod)
 {
     VALUE p, ary = rb_ary_new();
+    VALUE refined_class = Qnil;
+    if (FL_TEST(mod, RMODULE_IS_REFINEMENT)) {
+        refined_class = rb_refinement_module_get_refined_class(mod);
+    }
 
     for (p = mod; p; p = RCLASS_SUPER(p)) {
+        if (p == refined_class) break;
         if (p != RCLASS_ORIGIN(p)) continue;
 	if (BUILTIN_TYPE(p) == T_ICLASS) {
 	    rb_ary_push(ary, RBASIC(p)->klass);
diff --git a/test/ruby/test_refinement.rb b/test/ruby/test_refinement.rb
index 14c112f..822de47 100644
--- a/test/ruby/test_refinement.rb
+++ b/test/ruby/test_refinement.rb
@@ -2559,6 +2559,18 @@ class TestRefinement < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_refinement.rb#L2559
     assert_equal(:refined, Bug17822::Client.call_foo)
   end
 
+  def test_ancestors
+    refinement = nil
+    as = nil
+    Module.new do
+      refine Array do
+        refinement = self
+        as = ancestors
+      end
+    end
+    assert_equal([refinement], as, "[ruby-core:86949] [Bug #14744]")
+  end
+
   private
 
   def eval_using(mod, s)
-- 
cgit v1.1


--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]