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

ruby-changes:46511

From: nagachika <ko1@a...>
Date: Wed, 10 May 2017 00:06:06 +0900 (JST)
Subject: [ruby-changes:46511] nagachika:r58632 (ruby_2_4): merge revision(s) 58082, 58083: [Backport #13236]

nagachika	2017-05-10 00:05:59 +0900 (Wed, 10 May 2017)

  New Revision: 58632

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

  Log:
    merge revision(s) 58082,58083: [Backport #13236]
    
    class.c: ensure_includable
    
    * class.c (ensure_includable): extract checks to include and
      prepend.
    class.c: prohibit refinement module
    
    * class.c (ensure_includable): cannot include refinement
      module, or the type and the class do not match.
      [ruby-core:79632] [Bug #13236]

  Modified directories:
    branches/ruby_2_4/
  Modified files:
    branches/ruby_2_4/class.c
    branches/ruby_2_4/test/ruby/test_refinement.rb
    branches/ruby_2_4/version.h
Index: ruby_2_4/class.c
===================================================================
--- ruby_2_4/class.c	(revision 58631)
+++ ruby_2_4/class.c	(revision 58632)
@@ -849,14 +849,23 @@ rb_include_class_new(VALUE module, VALUE https://github.com/ruby/ruby/blob/trunk/ruby_2_4/class.c#L849
 
 static int include_modules_at(const VALUE klass, VALUE c, VALUE module, int search_super);
 
+static void
+ensure_includable(VALUE klass, VALUE module)
+{
+    rb_frozen_class_p(klass);
+    Check_Type(module, T_MODULE);
+    if (!NIL_P(rb_refinement_module_get_refined_class(module))) {
+	rb_raise(rb_eArgError, "refinement module is not allowed");
+    }
+    OBJ_INFECT(klass, module);
+}
+
 void
 rb_include_module(VALUE klass, VALUE module)
 {
     int changed = 0;
 
-    rb_frozen_class_p(klass);
-    Check_Type(module, T_MODULE);
-    OBJ_INFECT(klass, module);
+    ensure_includable(klass, module);
 
     changed = include_modules_at(klass, RCLASS_ORIGIN(klass), module, TRUE);
     if (changed < 0)
@@ -966,9 +975,7 @@ rb_prepend_module(VALUE klass, VALUE mod https://github.com/ruby/ruby/blob/trunk/ruby_2_4/class.c#L975
     VALUE origin;
     int changed = 0;
 
-    rb_frozen_class_p(klass);
-    Check_Type(module, T_MODULE);
-    OBJ_INFECT(klass, module);
+    ensure_includable(klass, module);
 
     origin = RCLASS_ORIGIN(klass);
     if (origin == klass) {
Index: ruby_2_4/version.h
===================================================================
--- ruby_2_4/version.h	(revision 58631)
+++ ruby_2_4/version.h	(revision 58632)
@@ -1,6 +1,6 @@ https://github.com/ruby/ruby/blob/trunk/ruby_2_4/version.h#L1
 #define RUBY_VERSION "2.4.2"
 #define RUBY_RELEASE_DATE "2017-05-09"
-#define RUBY_PATCHLEVEL 126
+#define RUBY_PATCHLEVEL 127
 
 #define RUBY_RELEASE_YEAR 2017
 #define RUBY_RELEASE_MONTH 5
Index: ruby_2_4/test/ruby/test_refinement.rb
===================================================================
--- ruby_2_4/test/ruby/test_refinement.rb	(revision 58631)
+++ ruby_2_4/test/ruby/test_refinement.rb	(revision 58632)
@@ -1886,6 +1886,20 @@ class TestRefinement < Test::Unit::TestC https://github.com/ruby/ruby/blob/trunk/ruby_2_4/test/ruby/test_refinement.rb#L1886
     assert_equal("Parent -> Child", SuperToModule::Child.test, bug)
   end
 
+  def test_include_refinement
+    bug = '[ruby-core:79632] [Bug #13236] cannot include refinement module'
+    r = nil
+    m = Module.new do
+      r = refine(String) {def test;:ok end}
+    end
+    assert_raise_with_message(ArgumentError, /refinement/, bug) do
+      m.module_eval {include r}
+    end
+    assert_raise_with_message(ArgumentError, /refinement/, bug) do
+      m.module_eval {prepend r}
+    end
+  end
+
   private
 
   def eval_using(mod, s)
Index: ruby_2_4
===================================================================
--- ruby_2_4	(revision 58631)
+++ ruby_2_4	(revision 58632)

Property changes on: ruby_2_4
___________________________________________________________________
Modified: svn:mergeinfo
## -0,0 +0,1 ##
   Merged /trunk:r58082-58083

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

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