1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

proc.c: fix arity of rest keywords argument

* proc.c (rb_iseq_min_max_arity): maximum argument is unlimited if
  having rest keywords argument.  [ruby-core:53298] [Bug #8072]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@44413 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
nobu 2013-12-25 11:28:56 +00:00
parent c8185b327e
commit 7fd58845d9
4 changed files with 45 additions and 1 deletions

View file

@ -1,3 +1,8 @@
Wed Dec 25 20:28:48 2013 Nobuyoshi Nakada <nobu@ruby-lang.org>
* proc.c (rb_iseq_min_max_arity): maximum argument is unlimited if
having rest keywords argument. [ruby-core:53298] [Bug #8072]
Wed Dec 25 18:29:22 2013 Koichi Sasada <ko1@atdot.net>
* vm_insnhelper.c (argument_error): insert dummy frame to make

2
proc.c
View file

@ -877,7 +877,7 @@ proc_arity(VALUE self)
static inline int
rb_iseq_min_max_arity(const rb_iseq_t *iseq, int *max)
{
*max = iseq->arg_rest == -1 ?
*max = (iseq->arg_rest == -1 && iseq->arg_keyword == -1) ?
iseq->argc + iseq->arg_post_len + iseq->arg_opts - (iseq->arg_opts > 0)
: UNLIMITED_ARGUMENTS;
return iseq->argc + iseq->arg_post_len;

View file

@ -23,6 +23,13 @@ class TestMethod < Test::Unit::TestCase
def mo6(a, *b, c, &d) end
def mo7(a, b = nil, *c, d, &e) end
def ma1((a), &b) nil && a end
def mk1(**) end
def mk2(**o) nil && o end
def mk3(a, **o) nil && o end
def mk4(a = nil, **o) nil && o end
def mk5(a, b = nil, **o) nil && o end
def mk6(a, b = nil, c, **o) nil && o end
def mk7(a, b = nil, *c, d, **o) nil && o end
class Base
def foo() :base end
@ -68,6 +75,13 @@ class TestMethod < Test::Unit::TestCase
assert_equal(-2, method(:mo4).arity)
assert_equal(-3, method(:mo5).arity)
assert_equal(-3, method(:mo6).arity)
assert_equal(-1, method(:mk1).arity)
assert_equal(-1, method(:mk2).arity)
assert_equal(-2, method(:mk3).arity)
assert_equal(-1, method(:mk4).arity)
assert_equal(-2, method(:mk5).arity)
assert_equal(-3, method(:mk6).arity)
assert_equal(-3, method(:mk7).arity)
end
def test_arity_special
@ -457,6 +471,13 @@ class TestMethod < Test::Unit::TestCase
define_method(:pmo6) {|a, *b, c, &d|}
define_method(:pmo7) {|a, b = nil, *c, d, &e|}
define_method(:pma1) {|(a), &b| nil && a}
define_method(:pmk1) {|**|}
define_method(:pmk2) {|**o|}
define_method(:pmk3) {|a, **o|}
define_method(:pmk4) {|a = nil, **o|}
define_method(:pmk5) {|a, b = nil, **o|}
define_method(:pmk6) {|a, b = nil, c, **o|}
define_method(:pmk7) {|a, b = nil, *c, d, **o|}
def test_bound_parameters
assert_equal([], method(:m0).parameters)

View file

@ -77,6 +77,13 @@ 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(-3, proc{|x, y=0, *z, w, **o|}.arity)
assert_equal(0, lambda{}.arity)
assert_equal(0, lambda{||}.arity)
@ -95,6 +102,13 @@ class TestProc < Test::Unit::TestCase
assert_equal(2, lambda{|(x, y), z|[x,y]}.arity)
assert_equal(-2, lambda{|(x, y), z=0|[x,y]}.arity)
assert_equal(-4, lambda{|x, *y, z, a|}.arity)
assert_equal(-1, lambda{|**|}.arity)
assert_equal(-1, lambda{|**o|}.arity)
assert_equal(-2, lambda{|x, **o|}.arity)
assert_equal(-1, lambda{|x=0, **o|}.arity)
assert_equal(-2, lambda{|x, y=0, **o|}.arity)
assert_equal(-3, lambda{|x, y=0, z, **o|}.arity)
assert_equal(-3, lambda{|x, y=0, *z, w, **o|}.arity)
assert_arity(0) {}
assert_arity(0) {||}
@ -104,6 +118,10 @@ class TestProc < Test::Unit::TestCase
assert_arity(-3) {|x, *y, z|}
assert_arity(-1) {|*x|}
assert_arity(-1) {|*|}
assert_arity(-1) {|**o|}
assert_arity(-1) {|**|}
assert_arity(-2) {|x, *y, **|}
assert_arity(-3) {|x, *y, z, **|}
end
def m(x)