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

ruby-changes:61473

From: Nobuyoshi <ko1@a...>
Date: Thu, 4 Jun 2020 02:13:16 +0900 (JST)
Subject: [ruby-changes:61473] 8340c773e5 (master): Properly resolve refinements in defined? on method call [Bug #16932]

https://git.ruby-lang.org/ruby.git/commit/?id=8340c773e5

From 8340c773e54feb399c9fab322e3ff6dd578ac04d Mon Sep 17 00:00:00 2001
From: Nobuyoshi Nakada <nobu@r...>
Date: Wed, 3 Jun 2020 23:05:55 +0900
Subject: Properly resolve refinements in defined? on method call [Bug #16932]


diff --git a/test/ruby/test_defined.rb b/test/ruby/test_defined.rb
index e1571d5..6ad4854 100644
--- a/test/ruby/test_defined.rb
+++ b/test/ruby/test_defined.rb
@@ -301,4 +301,32 @@ class TestDefined < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_defined.rb#L301
   def test_top_level_constant_not_defined
     assert_nil(defined?(TestDefined::Object))
   end
+
+  class RefinedClass
+  end
+
+  module RefiningModule
+    refine RefinedClass do
+      def pub
+      end
+    end
+
+    def self.call_without_using(x = RefinedClass.new)
+      defined?(x.pub)
+    end
+
+    using self
+
+    def self.call_with_using(x = RefinedClass.new)
+      defined?(x.pub)
+    end
+  end
+
+  def test_defined_refined_call_without_using
+    assert(!RefiningModule.call_without_using, "refined public method without using")
+  end
+
+  def test_defined_refined_call_with_using
+    assert(RefiningModule.call_with_using, "refined public method with using")
+  end
 end
diff --git a/vm_insnhelper.c b/vm_insnhelper.c
index 6c82d74..f910c03 100644
--- a/vm_insnhelper.c
+++ b/vm_insnhelper.c
@@ -3660,7 +3660,7 @@ vm_defined(rb_execution_context_t *ec, rb_control_frame_t *reg_cfp, rb_num_t op_ https://github.com/ruby/ruby/blob/trunk/vm_insnhelper.c#L3660
 	break;
       case DEFINED_METHOD:{
 	VALUE klass = CLASS_OF(v);
-	const rb_method_entry_t *me = rb_method_entry(klass, SYM2ID(obj));
+	const rb_method_entry_t *me = rb_method_entry_with_refinements(klass, SYM2ID(obj), NULL);
 
 	if (me) {
 	    switch (METHOD_ENTRY_VISI(me)) {
diff --git a/vm_method.c b/vm_method.c
index 0c4c26a..a87a8f3 100644
--- a/vm_method.c
+++ b/vm_method.c
@@ -1088,7 +1088,7 @@ method_entry_resolve_refinement(VALUE klass, ID id, int with_refinement, VALUE * https://github.com/ruby/ruby/blob/trunk/vm_method.c#L1088
     return me;
 }
 
-const rb_method_entry_t *
+MJIT_FUNC_EXPORTED const rb_method_entry_t *
 rb_method_entry_with_refinements(VALUE klass, ID id, VALUE *defined_class_ptr)
 {
     return method_entry_resolve_refinement(klass, id, TRUE, defined_class_ptr);
-- 
cgit v0.10.2


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

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