diff --git a/ChangeLog b/ChangeLog index f2592eb9f6..819c6fe4f2 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +Sat Mar 1 21:00:27 2014 Marc-Andre Lafortune + + * proc.c: Having optional keyword arguments makes maximum arity +1, + not unlimited [#8072] + Sat Mar 1 17:25:12 2014 Marc-Andre Lafortune * proc.c: Having any mandatory keyword argument increases min arity diff --git a/proc.c b/proc.c index 9c88ada316..e3cecb7bbe 100644 --- a/proc.c +++ b/proc.c @@ -825,8 +825,9 @@ proc_arity(VALUE self) 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 + (iseq->arg_keyword_required > 0); } diff --git a/test/ruby/test_proc.rb b/test/ruby/test_proc.rb index 9e8fb06d6d..1c8a053cca 100644 --- a/test/ruby/test_proc.rb +++ b/test/ruby/test_proc.rb @@ -77,12 +77,12 @@ class TestProc < Test::Unit::TestCase 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(2, proc{|x, y=0, z, a:1|}.arity) diff --git a/version.h b/version.h index 59c80e3828..746643bda1 100644 --- a/version.h +++ b/version.h @@ -1,6 +1,6 @@ #define RUBY_VERSION "2.1.2" #define RUBY_RELEASE_DATE "2014-03-01" -#define RUBY_PATCHLEVEL 79 +#define RUBY_PATCHLEVEL 80 #define RUBY_RELEASE_YEAR 2014 #define RUBY_RELEASE_MONTH 3