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

ruby-changes:32353

From: marcandre <ko1@a...>
Date: Thu, 26 Dec 2013 06:29:24 +0900 (JST)
Subject: [ruby-changes:32353] marcandRe: r44432 (trunk): * proc.c: Having optional keyword arguments makes maximum arity +1, not unlimited [#8072]

marcandre	2013-12-26 06:27:48 +0900 (Thu, 26 Dec 2013)

  New Revision: 44432

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

  Log:
    * proc.c: Having optional keyword arguments makes maximum arity +1, not unlimited [#8072]

  Modified files:
    trunk/ChangeLog
    trunk/proc.c
    trunk/test/ruby/test_proc.rb
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 44431)
+++ ChangeLog	(revision 44432)
@@ -1,3 +1,8 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Thu Dec 26 06:27:08 2013  Marc-Andre Lafortune  <ruby-core@m...>
+
+	* proc.c: Having optional keyword arguments makes maximum arity +1,
+	  not unlimited [#8072]
+
 Thu Dec 26 01:09:57 2013  NAKAMURA Usaku  <usa@r...>
 
 	* tool/release.sh: make symbolic links.
Index: proc.c
===================================================================
--- proc.c	(revision 44431)
+++ proc.c	(revision 44432)
@@ -877,8 +877,9 @@ 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 && iseq->arg_keyword == -1) ?
-        iseq->argc + iseq->arg_post_len + iseq->arg_opts - (iseq->arg_opts > 0)
+    *max = iseq->arg_rest == -1 ?
+	iseq->argc + iseq->arg_post_len + iseq->arg_opts -
+	(iseq->arg_opts > 0) + (iseq->arg_keyword != -1)
       : UNLIMITED_ARGUMENTS;
     return iseq->argc + iseq->arg_post_len;
 }
Index: test/ruby/test_proc.rb
===================================================================
--- test/ruby/test_proc.rb	(revision 44431)
+++ test/ruby/test_proc.rb	(revision 44432)
@@ -77,12 +77,12 @@ 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(0, proc{|**|}.arity)
+    assert_equal(0, proc{|**o|}.arity)
+    assert_equal(1, proc{|x, **o|}.arity)
+    assert_equal(0, proc{|x=0, **o|}.arity)
+    assert_equal(1, proc{|x, y=0, **o|}.arity)
+    assert_equal(2, proc{|x, y=0, z, **o|}.arity)
     assert_equal(-3, proc{|x, y=0, *z, w, **o|}.arity)
 
     assert_equal(0, lambda{}.arity)

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

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