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

ruby-changes:65017

From: Nobuyoshi <ko1@a...>
Date: Sat, 23 Jan 2021 20:02:55 +0900 (JST)
Subject: [ruby-changes:65017] 8dfae85adb (master): Warn the defined location as deprecation as well as the main message

https://git.ruby-lang.org/ruby.git/commit/?id=8dfae85adb

From 8dfae85adb96cf3da84bf38f2103969d4a7aed3f Mon Sep 17 00:00:00 2001
From: Nobuyoshi Nakada <nobu@r...>
Date: Sat, 23 Jan 2021 19:57:07 +0900
Subject: Warn the defined location as deprecation as well as the main message

[Bug #17575]
---
 test/ruby/test_defined.rb | 17 +++++++++++++++++
 vm_method.c               |  3 ++-
 2 files changed, 19 insertions(+), 1 deletion(-)

diff --git a/test/ruby/test_defined.rb b/test/ruby/test_defined.rb
index b22db70..73c192a 100644
--- a/test/ruby/test_defined.rb
+++ b/test/ruby/test_defined.rb
@@ -258,6 +258,23 @@ class TestDefined < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_defined.rb#L258
     assert_separately([], "assert_nil(defined?(super))")
   end
 
+  def test_respond_to
+    obj = "#{self.class.name}##{__method__}"
+    class << obj
+      def respond_to?(mid)
+        true
+      end
+    end
+    assert_warn(/deprecated method signature.*\n.*respond_to\? is defined here/) do
+      Warning[:deprecated] = true
+      defined?(obj.foo)
+    end
+    assert_warn('') do
+      Warning[:deprecated] = false
+      defined?(obj.foo)
+    end
+  end
+
   class ExampleRespondToMissing
     attr_reader :called
 
diff --git a/vm_method.c b/vm_method.c
index c4eb3dd..dd00e52 100644
--- a/vm_method.c
+++ b/vm_method.c
@@ -2503,7 +2503,8 @@ vm_respond_to(rb_execution_context_t *ec, VALUE klass, VALUE obj, ID id, int pri https://github.com/ruby/ruby/blob/trunk/vm_method.c#L2503
 		    VALUE path = RARRAY_AREF(location, 0);
 		    VALUE line = RARRAY_AREF(location, 1);
 		    if (!NIL_P(path)) {
-			rb_compile_warn(RSTRING_PTR(path), NUM2INT(line),
+			rb_category_compile_warn(RB_WARN_CATEGORY_DEPRECATED,
+					RSTRING_PTR(path), NUM2INT(line),
 					"respond_to? is defined here");
 		    }
 		}
-- 
cgit v1.1


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

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