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

ruby-changes:58962

From: Jeremy <ko1@a...>
Date: Sat, 30 Nov 2019 03:32:27 +0900 (JST)
Subject: [ruby-changes:58962] 0c273b2279 (master): Supress class variable overtaken warning when original modules are the same

https://git.ruby-lang.org/ruby.git/commit/?id=0c273b2279

From 0c273b2279e65c57161e0859f2d4e9f6e649b751 Mon Sep 17 00:00:00 2001
From: Jeremy Evans <code@j...>
Date: Thu, 28 Nov 2019 17:28:13 -0800
Subject: Supress class variable overtaken warning when original modules are
 the same

This issue was exposed by recent commits to better support including
refined modules.

diff --git a/test/ruby/test_variable.rb b/test/ruby/test_variable.rb
index 6ed956c..b053e11 100644
--- a/test/ruby/test_variable.rb
+++ b/test/ruby/test_variable.rb
@@ -63,6 +63,29 @@ class TestVariable < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_variable.rb#L63
     assert_equal(1, o.singleton_class.class_variable_get(:@@foo))
   end
 
+  class IncludeRefinedModuleClassVariableNoWarning
+    module Mod
+      @@_test_include_refined_module_class_variable = true
+    end
+
+    module Mod2
+      refine Mod do
+      end
+    end
+
+    include Mod
+
+    def t
+      @@_test_include_refined_module_class_variable
+    end
+  end
+
+  def test_include_refined_module_class_variable
+    assert_warning('') do
+      IncludeRefinedModuleClassVariableNoWarning.new.t
+    end
+  end
+
   def test_variable
     assert_instance_of(Integer, $$)
 
diff --git a/variable.c b/variable.c
index 9919e48..9c50b75 100644
--- a/variable.c
+++ b/variable.c
@@ -3025,7 +3025,7 @@ cvar_overtaken(VALUE front, VALUE target, ID id) https://github.com/ruby/ruby/blob/trunk/variable.c#L3025
     if (front && target != front) {
 	st_data_t did = (st_data_t)id;
 
-	if (RTEST(ruby_verbose)) {
+        if (RTEST(ruby_verbose) && original_module(front) != original_module(target)) {
 	    rb_warning("class variable % "PRIsVALUE" of %"PRIsVALUE" is overtaken by %"PRIsVALUE"",
 		       ID2SYM(id), rb_class_name(original_module(front)),
 		       rb_class_name(original_module(target)));
-- 
cgit v0.10.2


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

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