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

ruby-changes:50693

From: naruse <ko1@a...>
Date: Tue, 20 Mar 2018 18:52:59 +0900 (JST)
Subject: [ruby-changes:50693] naruse:r62860 (ruby_2_5): merge revision(s) 62725: [Backport #14604]

naruse	2018-03-20 18:52:52 +0900 (Tue, 20 Mar 2018)

  New Revision: 62860

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

  Log:
    merge revision(s) 62725: [Backport #14604]
    
    Fix setting method visibility on method wrapped with prepend
    
    Ignore prepended modules when looking for already defined methods on a
    class to set the visibility on.
    [Fix GH-1834]
    
    From: Dylan Thacker-Smith <Dylan.Smith@s...>

  Modified directories:
    branches/ruby_2_5/
  Modified files:
    branches/ruby_2_5/spec/ruby/core/module/private_spec.rb
    branches/ruby_2_5/test/ruby/test_module.rb
    branches/ruby_2_5/version.h
    branches/ruby_2_5/vm_method.c
Index: ruby_2_5/spec/ruby/core/module/private_spec.rb
===================================================================
--- ruby_2_5/spec/ruby/core/module/private_spec.rb	(revision 62859)
+++ ruby_2_5/spec/ruby/core/module/private_spec.rb	(revision 62860)
@@ -51,4 +51,43 @@ describe "Module#private" do https://github.com/ruby/ruby/blob/trunk/ruby_2_5/spec/ruby/core/module/private_spec.rb#L51
       Module.new.send(:private, :undefined)
     end.should raise_error(NameError)
   end
+
+  it "only makes the method private in the class it is called on" do
+    base = Class.new do
+      def wrapped
+        1
+      end
+    end
+
+    klass = Class.new(base) do
+      def wrapped
+        super + 1
+      end
+      private :wrapped
+    end
+
+    base.new.wrapped.should == 1
+    lambda do
+      klass.new.wrapped
+    end.should raise_error(NameError)
+  end
+
+  it "continues to allow a prepended module method to call super" do
+    wrapper = Module.new do
+      def wrapped
+        super + 1
+      end
+    end
+
+    klass = Class.new do
+      prepend wrapper
+
+      def wrapped
+        1
+      end
+      private :wrapped
+    end
+
+    klass.new.wrapped.should == 2
+  end
 end
Index: ruby_2_5/version.h
===================================================================
--- ruby_2_5/version.h	(revision 62859)
+++ ruby_2_5/version.h	(revision 62860)
@@ -1,6 +1,6 @@ https://github.com/ruby/ruby/blob/trunk/ruby_2_5/version.h#L1
 #define RUBY_VERSION "2.5.0"
 #define RUBY_RELEASE_DATE "2018-03-20"
-#define RUBY_PATCHLEVEL 46
+#define RUBY_PATCHLEVEL 47
 
 #define RUBY_RELEASE_YEAR 2018
 #define RUBY_RELEASE_MONTH 3
Index: ruby_2_5/vm_method.c
===================================================================
--- ruby_2_5/vm_method.c	(revision 62859)
+++ ruby_2_5/vm_method.c	(revision 62860)
@@ -1051,8 +1051,9 @@ rb_export_method(VALUE klass, ID name, r https://github.com/ruby/ruby/blob/trunk/ruby_2_5/vm_method.c#L1051
 {
     rb_method_entry_t *me;
     VALUE defined_class;
+    VALUE origin_class = RCLASS_ORIGIN(klass);
 
-    me = search_method(klass, name, &defined_class);
+    me = search_method(origin_class, name, &defined_class);
     if (!me && RB_TYPE_P(klass, T_MODULE)) {
 	me = search_method(rb_cObject, name, &defined_class);
     }
@@ -1065,7 +1066,7 @@ rb_export_method(VALUE klass, ID name, r https://github.com/ruby/ruby/blob/trunk/ruby_2_5/vm_method.c#L1066
     if (METHOD_ENTRY_VISI(me) != visi) {
 	rb_vm_check_redefinition_opt_method(me, klass);
 
-	if (klass == defined_class || RCLASS_ORIGIN(klass) == defined_class) {
+	if (klass == defined_class || origin_class == defined_class) {
 	    METHOD_ENTRY_VISI_SET(me, visi);
 
 	    if (me->def->type == VM_METHOD_TYPE_REFINED && me->def->body.refined.orig_me) {
Index: ruby_2_5/test/ruby/test_module.rb
===================================================================
--- ruby_2_5/test/ruby/test_module.rb	(revision 62859)
+++ ruby_2_5/test/ruby/test_module.rb	(revision 62860)
@@ -1876,6 +1876,25 @@ class TestModule < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/ruby_2_5/test/ruby/test_module.rb#L1876
     assert_raise(ArgumentError) { Module.new { prepend } }
   end
 
+  def test_prepend_private_super
+    wrapper = Module.new do
+      def wrapped
+        super + 1
+      end
+    end
+
+    klass = Class.new do
+      prepend wrapper
+
+      def wrapped
+        1
+      end
+      private :wrapped
+    end
+
+    assert_equal(2, klass.new.wrapped)
+  end
+
   def test_class_variables
     m = Module.new
     m.class_variable_set(:@@foo, 1)
Index: ruby_2_5
===================================================================
--- ruby_2_5	(revision 62859)
+++ ruby_2_5	(revision 62860)

Property changes on: ruby_2_5
___________________________________________________________________
Modified: svn:mergeinfo
## -0,0 +0,1 ##
   Merged /trunk:r62725

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

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