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

ruby-changes:24364

From: naruse <ko1@a...>
Date: Tue, 17 Jul 2012 16:48:06 +0900 (JST)
Subject: [ruby-changes:24364] naruse:r36415 (trunk): * proc.c (rb_proc_arity): return normal value (not -n-1) if it is not

naruse	2012-07-17 16:47:52 +0900 (Tue, 17 Jul 2012)

  New Revision: 36415

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

  Log:
    * proc.c (rb_proc_arity): return normal value (not -n-1) if it is not
      a labmda, or it is a labmda and no arg_opts. [Bug #5694]

  Modified files:
    trunk/ChangeLog
    trunk/proc.c

Index: ChangeLog
===================================================================
--- ChangeLog	(revision 36414)
+++ ChangeLog	(revision 36415)
@@ -1,3 +1,8 @@
+Tue Jul 17 16:41:32 2012  NARUSE, Yui  <naruse@r...>
+
+	* proc.c (rb_proc_arity): return normal value (not -n-1) if it is not
+	  a labmda, or it is a labmda and no arg_opts. [Bug #5694]
+
 Tue Jul 17 03:56:34 2012  Aaron Patterson <aaron@t...>
 
 	* ext/psych/lib/psych/visitors/to_ruby.rb: strings with YAML anchors
Index: proc.c
===================================================================
--- proc.c	(revision 36414)
+++ proc.c	(revision 36415)
@@ -630,6 +630,10 @@
  *     Proc.new {|*a|}.arity      #=> -1
  *     Proc.new {|a,*b|}.arity    #=> -2
  *     Proc.new {|a,*b, c|}.arity    #=> -3
+ *     lambda { |a = 0| }.arity      #=> -1
+ *     lambda { |a, b = 0| }.arity   #=> -2
+ *     lambda { |a, b = 0, c = 0| }.arity #=> -2
+ *     lambda { |(a, b), c = 0| }.arity   #=> -2
  */
 
 static VALUE
@@ -648,7 +652,7 @@
     iseq = proc->block.iseq;
     if (iseq) {
 	if (BUILTIN_TYPE(iseq) != T_NODE) {
-	    if (iseq->arg_rest < 0) {
+	    if (iseq->arg_rest < 0 && (!proc->is_lambda || iseq->arg_opts == 0)) {
 		return iseq->argc;
 	    }
 	    else {

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

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