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

ruby-changes:47329

From: nobu <ko1@a...>
Date: Sat, 29 Jul 2017 21:42:49 +0900 (JST)
Subject: [ruby-changes:47329] nobu:r59445 (trunk): visibility of inherited method

nobu	2017-07-29 21:42:42 +0900 (Sat, 29 Jul 2017)

  New Revision: 59445

  https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=59445

  Log:
    visibility of inherited method
    
    * vm_insnhelper.c (vm_call_method_each_type): honor the original
      visibility of inherited methods when a refinement is defined but
      not activated.  [ruby-core:82209] [Bug #13776]
    
    Author:    Mon_Ouie (Mon ou?\195?\175e) <mon.ouie@g...>

  Modified files:
    trunk/test/ruby/test_refinement.rb
    trunk/vm_insnhelper.c
Index: test/ruby/test_refinement.rb
===================================================================
--- test/ruby/test_refinement.rb	(revision 59444)
+++ test/ruby/test_refinement.rb	(revision 59445)
@@ -1900,6 +1900,50 @@ class TestRefinement < Test::Unit::TestC https://github.com/ruby/ruby/blob/trunk/test/ruby/test_refinement.rb#L1900
     end
   end
 
+  class ParentDefiningPrivateMethod
+    private
+    def some_inherited_method
+    end
+  end
+
+  module MixinDefiningPrivateMethod
+    private
+    def some_included_method
+    end
+  end
+
+  class SomeChildClassToRefine < ParentDefiningPrivateMethod
+    include MixinDefiningPrivateMethod
+
+    private
+    def some_method
+    end
+  end
+
+  def test_refine_inherited_method_with_visibility_changes
+    Module.new do
+      refine(SomeChildClassToRefine) do
+        def some_inherited_method; end
+        def some_included_method; end
+        def some_method; end
+      end
+    end
+
+    obj = SomeChildClassToRefine.new
+
+    assert_raise_with_message(NoMethodError, /private/) do
+      obj.some_inherited_method
+    end
+
+    assert_raise_with_message(NoMethodError, /private/) do
+      obj.some_included_method
+    end
+
+    assert_raise_with_message(NoMethodError, /private/) do
+      obj.some_method
+    end
+  end
+
   private
 
   def eval_using(mod, s)
Index: vm_insnhelper.c
===================================================================
--- vm_insnhelper.c	(revision 59444)
+++ vm_insnhelper.c	(revision 59445)
@@ -2283,11 +2283,12 @@ vm_call_method_each_type(rb_thread_t *th https://github.com/ruby/ruby/blob/trunk/vm_insnhelper.c#L2283
       no_refinement_dispatch:
 	if (cc->me->def->body.refined.orig_me) {
 	    cc->me = refined_method_callable_without_refinement(cc->me);
-	    return vm_call_method(th, cfp, calling, ci, cc);
 	}
 	else {
-	    return vm_call_zsuper(th, cfp, calling, ci, cc, cc->me->owner);
+	    VALUE klass = RCLASS_SUPER(cc->me->owner);
+	    cc->me = klass ? rb_callable_method_entry(klass, ci->mid) : NULL;
 	}
+	return vm_call_method(th, cfp, calling, ci, cc);
       }
     }
 

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

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