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

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@44432 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
marcandre 2013-12-25 21:27:48 +00:00
Родитель ab93604365
Коммит 43c3f447a4
3 изменённых файлов: 14 добавлений и 8 удалений

Просмотреть файл

@ -1,3 +1,8 @@
Thu Dec 26 06:27:08 2013 Marc-Andre Lafortune <ruby-core@marc-andre.ca>
* proc.c: Having optional keyword arguments makes maximum arity +1,
not unlimited [#8072]
Thu Dec 26 01:09:57 2013 NAKAMURA Usaku <usa@ruby-lang.org>
* tool/release.sh: make symbolic links.

5
proc.c
Просмотреть файл

@ -877,8 +877,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;
}

Просмотреть файл

@ -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(0, lambda{}.arity)