From c6dec376494db7886388b34943d4d3550fe99d09 Mon Sep 17 00:00:00 2001 From: marcandre Date: Thu, 1 Dec 2011 11:46:31 +0000 Subject: [PATCH] * proc.c (rb_proc_arity): Fix Proc#arity in case of optional arguments [bug #5694] [rubyspec:b8b259] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@33921 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ChangeLog | 5 +++++ proc.c | 18 +++++++++--------- 2 files changed, 14 insertions(+), 9 deletions(-) diff --git a/ChangeLog b/ChangeLog index 501079804c..2460234c88 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +Thu Dec 1 20:33:22 2011 Marc-Andre Lafortune + + * proc.c (rb_proc_arity): Fix Proc#arity in case of optional + arguments. [bug #5694] [rubyspec:b8b259] + Thu Dec 1 16:59:24 2011 Nobuyoshi Nakada * ext/socket/extconf.rb: add arguments for macro calls. diff --git a/proc.c b/proc.c index eeb8f09ae7..4d9f9baf5a 100644 --- a/proc.c +++ b/proc.c @@ -615,14 +615,14 @@ rb_proc_call_with_block(VALUE self, int argc, VALUE *argv, VALUE pass_procval) * arguments. A proc with no argument declarations * is the same a block declaring || as its arguments. * - * Proc.new {}.arity #=> 0 - * Proc.new {||}.arity #=> 0 - * Proc.new {|a|}.arity #=> 1 - * Proc.new {|a,b|}.arity #=> 2 - * Proc.new {|a,b,c|}.arity #=> 3 - * Proc.new {|*a|}.arity #=> -1 - * Proc.new {|a,*b|}.arity #=> -2 - * Proc.new {|a,*b, c|}.arity #=> -3 + * Proc.new {}.arity #=> 0 + * Proc.new {||}.arity #=> 0 + * Proc.new {|a|}.arity #=> 1 + * Proc.new {|a, b|}.arity #=> 2 + * Proc.new {|a, b, c|}.arity #=> 3 + * Proc.new {|*a|}.arity #=> -1 + * Proc.new {|a, b=42|}.arity #=> -2 + * Proc.new {|a, *b, c|}.arity #=> -3 */ static VALUE @@ -641,7 +641,7 @@ rb_proc_arity(VALUE self) iseq = proc->block.iseq; if (iseq) { if (BUILTIN_TYPE(iseq) != T_NODE) { - if (iseq->arg_rest < 0) { + if (iseq->arg_rest < 0 && iseq->arg_opts == 0) { return iseq->argc; } else {