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

ruby-changes:33059

From: naruse <ko1@a...>
Date: Sat, 22 Feb 2014 22:13:32 +0900 (JST)
Subject: [ruby-changes:33059] naruse:r45138 (ruby_2_1): merge revision(s) 44412, 44413, 44414, 44420, 44421: [Backport #9298]

naruse	2014-02-22 22:13:24 +0900 (Sat, 22 Feb 2014)

  New Revision: 45138

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=45138

  Log:
    merge revision(s) 44412,44413,44414,44420,44421: [Backport #9298]
    
    test_method.rb, test_proc.rb: suppress warnings
    
    * test/ruby/test_method.rb: suppress warnings in verbose mode.
    
    * test/ruby/test_proc.rb: ditto.
    * proc.c (rb_iseq_min_max_arity): maximum argument is unlimited if
      having rest keywords argument.  [ruby-core:53298] [Bug #8072]
    
    * iseq.c (rb_iseq_parameters): push argument type symbol only for
      unnamed rest keywords argument.
    
    * compile.c (iseq_set_arguments): set arg_keyword_check from
      nd_cflag, which is set by parser.  internal ID is used for
      unnamed keyword rest argument, which should be separated from no
      keyword check.
    
    * iseq.c (rb_iseq_parameters): if no keyword check, keyword rest is
      present.
    
    * parse.y (new_args_tail_gen): set keywords check to nd_cflag, which
      equals to that keyword rest is not present.

  Modified directories:
    branches/ruby_2_1/
  Modified files:
    branches/ruby_2_1/ChangeLog
    branches/ruby_2_1/compile.c
    branches/ruby_2_1/iseq.c
    branches/ruby_2_1/parse.y
    branches/ruby_2_1/proc.c
    branches/ruby_2_1/test/ruby/test_keyword.rb
    branches/ruby_2_1/test/ruby/test_method.rb
    branches/ruby_2_1/test/ruby/test_proc.rb
    branches/ruby_2_1/version.h
Index: ruby_2_1/ChangeLog
===================================================================
--- ruby_2_1/ChangeLog	(revision 45137)
+++ ruby_2_1/ChangeLog	(revision 45138)
@@ -1,3 +1,26 @@ https://github.com/ruby/ruby/blob/trunk/ruby_2_1/ChangeLog#L1
+Sat Feb 22 21:56:26 2014  Nobuyoshi Nakada  <nobu@r...>
+
+	* compile.c (iseq_set_arguments): set arg_keyword_check from
+	  nd_cflag, which is set by parser.  internal ID is used for
+	  unnamed keyword rest argument, which should be separated from no
+	  keyword check.
+
+	* iseq.c (rb_iseq_parameters): if no keyword check, keyword rest is
+	  present.
+
+	* parse.y (new_args_tail_gen): set keywords check to nd_cflag, which
+	  equals to that keyword rest is not present.
+
+Sat Feb 22 21:56:26 2014  Nobuyoshi Nakada  <nobu@r...>
+
+	* iseq.c (rb_iseq_parameters): push argument type symbol only for
+	  unnamed rest keywords argument.
+
+Sat Feb 22 21:56:26 2014  Nobuyoshi Nakada  <nobu@r...>
+
+	* proc.c (rb_iseq_min_max_arity): maximum argument is unlimited if
+	  having rest keywords argument.  [ruby-core:53298] [Bug #8072]
+
 Sat Feb 22 18:55:08 2014  Shugo Maeda  <shugo@r...>
 
 	* ext/socket/init.c (wait_connectable): break if the socket is
Index: ruby_2_1/iseq.c
===================================================================
--- ruby_2_1/iseq.c	(revision 45137)
+++ ruby_2_1/iseq.c	(revision 45138)
@@ -2023,7 +2023,7 @@ rb_iseq_parameters(const rb_iseq_t *iseq https://github.com/ruby/ruby/blob/trunk/ruby_2_1/iseq.c#L2023
 	    }
 	    rb_ary_push(args, a);
 	}
-	if (rb_id2str(iseq->local_table[iseq->arg_keyword])) {
+	if (!iseq->arg_keyword_check) {
 	    CONST_ID(keyrest, "keyrest");
 	    rb_ary_push(args, PARAM(iseq->arg_keyword, keyrest));
 	}
Index: ruby_2_1/compile.c
===================================================================
--- ruby_2_1/compile.c	(revision 45137)
+++ ruby_2_1/compile.c	(revision 45138)
@@ -1203,7 +1203,7 @@ iseq_set_arguments(rb_iseq_t *iseq, LINK https://github.com/ruby/ruby/blob/trunk/ruby_2_1/compile.c#L1203
 		node = node->nd_next;
 		i += 1;
 	    }
-	    iseq->arg_keyword_check = (args->kw_rest_arg->nd_vid & ID_SCOPE_MASK) == ID_JUNK;
+	    iseq->arg_keyword_check = args->kw_rest_arg->nd_cflag != 0;
 	    iseq->arg_keywords = i;
 	    iseq->arg_keyword_required = r;
 	    iseq->arg_keyword_table = ALLOC_N(ID, i);
Index: ruby_2_1/proc.c
===================================================================
--- ruby_2_1/proc.c	(revision 45137)
+++ ruby_2_1/proc.c	(revision 45138)
@@ -825,7 +825,7 @@ proc_arity(VALUE self) https://github.com/ruby/ruby/blob/trunk/ruby_2_1/proc.c#L825
 static inline int
 rb_iseq_min_max_arity(const rb_iseq_t *iseq, int *max)
 {
-    *max = iseq->arg_rest == -1 ?
+    *max = (iseq->arg_rest == -1 && iseq->arg_keyword == -1) ?
         iseq->argc + iseq->arg_post_len + iseq->arg_opts - (iseq->arg_opts > 0)
       : UNLIMITED_ARGUMENTS;
     return iseq->argc + iseq->arg_post_len;
Index: ruby_2_1/parse.y
===================================================================
--- ruby_2_1/parse.y	(revision 45137)
+++ ruby_2_1/parse.y	(revision 45138)
@@ -9486,6 +9486,7 @@ new_args_tail_gen(struct parser_params * https://github.com/ruby/ruby/blob/trunk/ruby_2_1/parse.y#L9486
     struct rb_args_info *args;
     NODE *kw_rest_arg = 0;
     NODE *node;
+    int check = 0;
 
     args = ALLOC(struct rb_args_info);
     MEMZERO(args, struct rb_args_info, 1);
@@ -9493,10 +9494,14 @@ new_args_tail_gen(struct parser_params * https://github.com/ruby/ruby/blob/trunk/ruby_2_1/parse.y#L9494
 
     args->block_arg      = b;
     args->kw_args        = k;
-    if (k && !kr) kr = internal_id();
+    if (k && !kr) {
+	check = 1;
+	kr = internal_id();
+    }
     if (kr) {
 	arg_var(kr);
 	kw_rest_arg  = NEW_DVAR(kr);
+	kw_rest_arg->nd_cflag = check;
     }
     args->kw_rest_arg    = kw_rest_arg;
 
Index: ruby_2_1/version.h
===================================================================
--- ruby_2_1/version.h	(revision 45137)
+++ ruby_2_1/version.h	(revision 45138)
@@ -1,6 +1,6 @@ https://github.com/ruby/ruby/blob/trunk/ruby_2_1/version.h#L1
 #define RUBY_VERSION "2.1.1"
 #define RUBY_RELEASE_DATE "2014-02-22"
-#define RUBY_PATCHLEVEL 73
+#define RUBY_PATCHLEVEL 74
 
 #define RUBY_RELEASE_YEAR 2014
 #define RUBY_RELEASE_MONTH 2
Index: ruby_2_1/test/ruby/test_keyword.rb
===================================================================
--- ruby_2_1/test/ruby/test_keyword.rb	(revision 45137)
+++ ruby_2_1/test/ruby/test_keyword.rb	(revision 45138)
@@ -117,6 +117,15 @@ class TestKeywordArguments < Test::Unit: https://github.com/ruby/ruby/blob/trunk/ruby_2_1/test/ruby/test_keyword.rb#L117
     assert_equal([1, 2, [3, 4], 5, :key, {str: "bar"}, nil], f9(1, 2, 3, 4, 5, str: "bar"))
   end
 
+  def f10(a: 1, **)
+    a
+  end
+
+  def test_f10
+    assert_equal(42, f10(a: 42))
+    assert_equal(1, f10(b: 42))
+  end
+
   def test_method_parameters
     assert_equal([[:key, :str], [:key, :num]], method(:f1).parameters);
     assert_equal([[:req, :x], [:key, :str], [:key, :num]], method(:f2).parameters);
Index: ruby_2_1/test/ruby/test_proc.rb
===================================================================
--- ruby_2_1/test/ruby/test_proc.rb	(revision 45137)
+++ ruby_2_1/test/ruby/test_proc.rb	(revision 45138)
@@ -77,6 +77,13 @@ class TestProc < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/ruby_2_1/test/ruby/test_proc.rb#L77
     assert_equal(2, proc{|(x, y), z|[x,y]}.arity)
     assert_equal(1, proc{|(x, y), z=0|[x,y]}.arity)
     assert_equal(-4, proc{|x, *y, z, a|}.arity)
+    assert_equal(-1, proc{|**|}.arity)
+    assert_equal(-1, proc{|**o|}.arity)
+    assert_equal(-2, proc{|x, **o|}.arity)
+    assert_equal(-1, proc{|x=0, **o|}.arity)
+    assert_equal(-2, proc{|x, y=0, **o|}.arity)
+    assert_equal(-3, proc{|x, y=0, z, **o|}.arity)
+    assert_equal(-3, proc{|x, y=0, *z, w, **o|}.arity)
 
     assert_equal(0, lambda{}.arity)
     assert_equal(0, lambda{||}.arity)
@@ -95,6 +102,13 @@ class TestProc < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/ruby_2_1/test/ruby/test_proc.rb#L102
     assert_equal(2, lambda{|(x, y), z|[x,y]}.arity)
     assert_equal(-2, lambda{|(x, y), z=0|[x,y]}.arity)
     assert_equal(-4, lambda{|x, *y, z, a|}.arity)
+    assert_equal(-1, lambda{|**|}.arity)
+    assert_equal(-1, lambda{|**o|}.arity)
+    assert_equal(-2, lambda{|x, **o|}.arity)
+    assert_equal(-1, lambda{|x=0, **o|}.arity)
+    assert_equal(-2, lambda{|x, y=0, **o|}.arity)
+    assert_equal(-3, lambda{|x, y=0, z, **o|}.arity)
+    assert_equal(-3, lambda{|x, y=0, *z, w, **o|}.arity)
 
     assert_arity(0) {}
     assert_arity(0) {||}
@@ -104,6 +118,10 @@ class TestProc < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/ruby_2_1/test/ruby/test_proc.rb#L118
     assert_arity(-3) {|x, *y, z|}
     assert_arity(-1) {|*x|}
     assert_arity(-1) {|*|}
+    assert_arity(-1) {|**o|}
+    assert_arity(-1) {|**|}
+    assert_arity(-2) {|x, *y, **|}
+    assert_arity(-3) {|x, *y, z, **|}
   end
 
   def m(x)
@@ -1086,6 +1104,13 @@ class TestProc < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/ruby_2_1/test/ruby/test_proc.rb#L1104
   def pmo6(a, *b, c, &d) end
   def pmo7(a, b = :b, *c, d, &e) end
   def pma1((a), &b) a; end
+  def pmk1(**) end
+  def pmk2(**o) nil && o end
+  def pmk3(a, **o) nil && o end
+  def pmk4(a = nil, **o) nil && o end
+  def pmk5(a, b = nil, **o) nil && o end
+  def pmk6(a, b = nil, c, **o) nil && o end
+  def pmk7(a, b = nil, *c, d, **o) nil && o end
 
 
   def test_bound_parameters
@@ -1100,6 +1125,13 @@ class TestProc < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/ruby_2_1/test/ruby/test_proc.rb#L1125
     assert_equal([[:req, :a], [:rest, :b], [:req, :c], [:block, :d]], method(:pmo6).to_proc.parameters)
     assert_equal([[:req, :a], [:opt, :b], [:rest, :c], [:req, :d], [:block, :e]], method(:pmo7).to_proc.parameters)
     assert_equal([[:req], [:block, :b]], method(:pma1).to_proc.parameters)
+    assert_equal([[:keyrest]], method(:pmk1).to_proc.parameters)
+    assert_equal([[:keyrest, :o]], method(:pmk2).to_proc.parameters)
+    assert_equal([[:req, :a], [:keyrest, :o]], method(:pmk3).to_proc.parameters)
+    assert_equal([[:opt, :a], [:keyrest, :o]], method(:pmk4).to_proc.parameters)
+    assert_equal([[:req, :a], [:opt, :b], [:keyrest, :o]], method(:pmk5).to_proc.parameters)
+    assert_equal([[:req, :a], [:opt, :b], [:req, :c], [:keyrest, :o]], method(:pmk6).to_proc.parameters)
+    assert_equal([[:req, :a], [:opt, :b], [:rest, :c], [:req, :d], [:keyrest, :o]], method(:pmk7).to_proc.parameters)
 
     assert_equal([], "".method(:upcase).to_proc.parameters)
     assert_equal([[:rest]], "".method(:gsub).to_proc.parameters)
@@ -1209,7 +1241,7 @@ class TestProc < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/ruby_2_1/test/ruby/test_proc.rb#L1241
   end
 
   def get_binding if: 1, case: 2, when: 3, begin: 4, end: 5
-    a = 0
+    a ||= 0
     binding
   end
 
Index: ruby_2_1/test/ruby/test_method.rb
===================================================================
--- ruby_2_1/test/ruby/test_method.rb	(revision 45137)
+++ ruby_2_1/test/ruby/test_method.rb	(revision 45138)
@@ -22,7 +22,14 @@ class TestMethod < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/ruby_2_1/test/ruby/test_method.rb#L22
   def mo5(a, *b, c) end
   def mo6(a, *b, c, &d) end
   def mo7(a, b = nil, *c, d, &e) end
-  def ma1((a), &b) end
+  def ma1((a), &b) nil && a end
+  def mk1(**) end
+  def mk2(**o) nil && o end
+  def mk3(a, **o) nil && o end
+  def mk4(a = nil, **o) nil && o end
+  def mk5(a, b = nil, **o) nil && o end
+  def mk6(a, b = nil, c, **o) nil && o end
+  def mk7(a, b = nil, *c, d, **o) nil && o end
 
   class Base
     def foo() :base end
@@ -68,6 +75,13 @@ class TestMethod < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/ruby_2_1/test/ruby/test_method.rb#L75
     assert_equal(-2, method(:mo4).arity)
     assert_equal(-3, method(:mo5).arity)
     assert_equal(-3, method(:mo6).arity)
+    assert_equal(-1, method(:mk1).arity)
+    assert_equal(-1, method(:mk2).arity)
+    assert_equal(-2, method(:mk3).arity)
+    assert_equal(-1, method(:mk4).arity)
+    assert_equal(-2, method(:mk5).arity)
+    assert_equal(-3, method(:mk6).arity)
+    assert_equal(-3, method(:mk7).arity)
   end
 
   def test_arity_special
@@ -293,7 +307,7 @@ class TestMethod < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/ruby_2_1/test/ruby/test_method.rb#L307
       end
     end
 
-    assert_nothing_raised do
+    assert_nothing_raised(bug8686) do
       m.define_singleton_method(:a, m.method(:a))
     end
   end
@@ -456,7 +470,14 @@ class TestMethod < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/ruby_2_1/test/ruby/test_method.rb#L470
   define_method(:pmo5) {|a, *b, c|}
   define_method(:pmo6) {|a, *b, c, &d|}
   define_method(:pmo7) {|a, b = nil, *c, d, &e|}
-  define_method(:pma1) {|(a), &b|}
+  define_method(:pma1) {|(a), &b| nil && a}
+  define_method(:pmk1) {|**|}
+  define_method(:pmk2) {|**o|}
+  define_method(:pmk3) {|a, **o|}
+  define_method(:pmk4) {|a = nil, **o|}
+  define_method(:pmk5) {|a, b = nil, **o|}
+  define_method(:pmk6) {|a, b = nil, c, **o|}
+  define_method(:pmk7) {|a, b = nil, *c, d, **o|}
 
   def test_bound_parameters
     assert_equal([], method(:m0).parameters)
@@ -470,6 +491,13 @@ class TestMethod < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/ruby_2_1/test/ruby/test_method.rb#L491
     assert_equal([[:req, :a], [:rest, :b], [:req, :c], [:block, :d]], method(:mo6).parameters)
     assert_equal([[:req, :a], [:opt, :b], [:rest, :c], [:req, :d], [:block, :e]], method(:mo7).parameters)
     assert_equal([[:req], [:block, :b]], method(:ma1).parameters)
+    assert_equal([[:keyrest]], method(:mk1).parameters)
+    assert_equal([[:keyrest, :o]], method(:mk2).parameters)
+    assert_equal([[:req, :a], [:keyrest, :o]], method(:mk3).parameters)
+    assert_equal([[:opt, :a], [:keyrest, :o]], method(:mk4).parameters)
+    assert_equal([[:req, :a], [:opt, :b], [:keyrest, :o]], method(:mk5).parameters)
+    assert_equal([[:req, :a], [:opt, :b], [:req, :c], [:keyrest, :o]], method(:mk6).parameters)
+    assert_equal([[:req, :a], [:opt, :b], [:rest, :c], [:req, :d], [:keyrest, :o]], method(:mk7).parameters)
   end
 
   def test_unbound_parameters
@@ -484,6 +512,13 @@ class TestMethod < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/ruby_2_1/test/ruby/test_method.rb#L512
     assert_equal([[:req, :a], [:rest, :b], [:req, :c], [:block, :d]], self.class.instance_method(:mo6).parameters)
     assert_equal([[:req, :a], [:opt, :b], [:rest, :c], [:req, :d], [:block, :e]], self.class.instance_method(:mo7).parameters)
     assert_equal([[:req], [:block, :b]], self.class.instance_method(:ma1).parameters)
+    assert_equal([[:keyrest]], self.class.instance_method(:mk1).parameters)
+    assert_equal([[:keyrest, :o]], self.class.instance_method(:mk2).parameters)
+    assert_equal([[:req, :a], [:keyrest, :o]], self.class.instance_method(:mk3).parameters)
+    assert_equal([[:opt, :a], [:keyrest, :o]], self.class.instance_method(:mk4).parameters)
+    assert_equal([[:req, :a], [:opt, :b], [:keyrest, :o]], self.class.instance_method(:mk5).parameters)
+    assert_equal([[:req, :a], [:opt, :b], [:req, :c], [:keyrest, :o]], self.class.instance_method(:mk6).parameters)
+    assert_equal([[:req, :a], [:opt, :b], [:rest, :c], [:req, :d], [:keyrest, :o]], self.class.instance_method(:mk7).parameters)
   end
 
   def test_bmethod_bound_parameters
@@ -498,6 +533,13 @@ class TestMethod < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/ruby_2_1/test/ruby/test_method.rb#L533
     assert_equal([[:req, :a], [:rest, :b], [:req, :c], [:block, :d]], method(:pmo6).parameters)
     assert_equal([[:req, :a], [:opt, :b], [:rest, :c], [:req, :d], [:block, :e]], method(:pmo7).parameters)
     assert_equal([[:req], [:block, :b]], method(:pma1).parameters)
+    assert_equal([[:keyrest]], method(:pmk1).parameters)
+    assert_equal([[:keyrest, :o]], method(:pmk2).parameters)
+    assert_equal([[:req, :a], [:keyrest, :o]], method(:pmk3).parameters)
+    assert_equal([[:opt, :a], [:keyrest, :o]], method(:pmk4).parameters)
+    assert_equal([[:req, :a], [:opt, :b], [:keyrest, :o]], method(:pmk5).parameters)
+    assert_equal([[:req, :a], [:opt, :b], [:req, :c], [:keyrest, :o]], method(:pmk6).parameters)
+    assert_equal([[:req, :a], [:opt, :b], [:rest, :c], [:req, :d], [:keyrest, :o]], method(:pmk7).parameters)
   end
 
   def test_bmethod_unbound_parameters
@@ -512,6 +554,14 @@ class TestMethod < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/ruby_2_1/test/ruby/test_method.rb#L554
     assert_equal([[:req, :a], [:rest, :b], [:req, :c], [:block, :d]], self.class.instance_method(:pmo6).parameters)
     assert_equal([[:req, :a], [:opt, :b], [:rest, :c], [:req, :d], [:block, :e]], self.class.instance_method(:pmo7).parameters)
     assert_equal([[:req], [:block, :b]], self.class.instance_method(:pma1).parameters)
+    assert_equal([[:req], [:block, :b]], self.class.instance_method(:pma1).parameters)
+    assert_equal([[:keyrest]], self.class.instance_method(:pmk1).parameters)
+    assert_equal([[:keyrest, :o]], self.class.instance_method(:pmk2).parameters)
+    assert_equal([[:req, :a], [:keyrest, :o]], self.class.instance_method(:pmk3).parameters)
+    assert_equal([[:opt, :a], [:keyrest, :o]], self.class.instance_method(:pmk4).parameters)
+    assert_equal([[:req, :a], [:opt, :b], [:keyrest, :o]], self.class.instance_method(:pmk5).parameters)
+    assert_equal([[:req, :a], [:opt, :b], [:req, :c], [:keyrest, :o]], self.class.instance_method(:pmk6).parameters)
+    assert_equal([[:req, :a], [:opt, :b], [:rest, :c], [:req, :d], [:keyrest, :o]], self.class.instance_method(:pmk7).parameters)
   end
 
   def test_public_method_with_zsuper_method
@@ -659,6 +709,7 @@ class TestMethod < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/ruby_2_1/test/ruby/test_method.rb#L709
       prepend m
     }
     assert_raise(NameError, bug7988) {Module.new{prepend m}.instance_method(:bar)}
+    true || c || bug7836
   end
 
   def test_gced_bmethod

Property changes on: ruby_2_1
___________________________________________________________________
Modified: svn:mergeinfo
   Merged /trunk:r44412-44414,44420-44421


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

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