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

ruby-changes:32334

From: nobu <ko1@a...>
Date: Wed, 25 Dec 2013 20:29:05 +0900 (JST)
Subject: [ruby-changes:32334] nobu:r44413 (trunk): proc.c: fix arity of rest keywords argument

nobu	2013-12-25 20:28:56 +0900 (Wed, 25 Dec 2013)

  New Revision: 44413

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

  Log:
    proc.c: fix arity of rest keywords argument
    
    * proc.c (rb_iseq_min_max_arity): maximum argument is unlimited if
      having rest keywords argument.  [ruby-core:53298] [Bug #8072]

  Modified files:
    trunk/ChangeLog
    trunk/proc.c
    trunk/test/ruby/test_method.rb
    trunk/test/ruby/test_proc.rb
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 44412)
+++ ChangeLog	(revision 44413)
@@ -1,3 +1,8 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Wed Dec 25 20:28:48 2013  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]
+
 Wed Dec 25 18:29:22 2013  Koichi Sasada  <ko1@a...>
 
 	* vm_insnhelper.c (argument_error): insert dummy frame to make
Index: proc.c
===================================================================
--- proc.c	(revision 44412)
+++ proc.c	(revision 44413)
@@ -877,7 +877,7 @@ proc_arity(VALUE self) https://github.com/ruby/ruby/blob/trunk/proc.c#L877
 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: test/ruby/test_proc.rb
===================================================================
--- test/ruby/test_proc.rb	(revision 44412)
+++ test/ruby/test_proc.rb	(revision 44413)
@@ -77,6 +77,13 @@ class TestProc < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/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/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/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)
Index: test/ruby/test_method.rb
===================================================================
--- test/ruby/test_method.rb	(revision 44412)
+++ test/ruby/test_method.rb	(revision 44413)
@@ -23,6 +23,13 @@ class TestMethod < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_method.rb#L23
   def mo6(a, *b, c, &d) end
   def mo7(a, b = nil, *c, d, &e) 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/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
@@ -457,6 +471,13 @@ class TestMethod < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_method.rb#L471
   define_method(:pmo6) {|a, *b, c, &d|}
   define_method(:pmo7) {|a, b = nil, *c, d, &e|}
   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)

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

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