summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormarcandre <marcandre@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2013-12-25 21:27:48 +0000
committermarcandre <marcandre@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2013-12-25 21:27:48 +0000
commit43c3f447a4d442e0b135220013c89f3742645b37 (patch)
tree4be1050243cde8f52971b45933b81bcdcd303e0f
parentab936043651396b3f2361cf5c515cf5d1a0a69d0 (diff)
* 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
-rw-r--r--ChangeLog5
-rw-r--r--proc.c5
-rw-r--r--test/ruby/test_proc.rb12
3 files changed, 14 insertions, 8 deletions
diff --git a/ChangeLog b/ChangeLog
index 0762642d3b..0c22cfcdbf 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -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.
diff --git a/proc.c b/proc.c
index 36f1653996..82f9e38ff2 100644
--- a/proc.c
+++ b/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;
}
diff --git a/test/ruby/test_proc.rb b/test/ruby/test_proc.rb
index 206e21fb1a..6c92f1e374 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(0, lambda{}.arity)