From 0ea1e43174a5b75682fc19789ea8dbeeb5b10ec6 Mon Sep 17 00:00:00 2001 From: nobu Date: Fri, 28 Dec 2012 02:50:57 +0000 Subject: vm_insnhelper.c: no splat single opt arg * vm_insnhelper.c (vm_yield_setup_block_args): pass single argument to single optional parameter unchanged without splatting. [Bug #7621] [ruby-dev:46801] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@38639 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ChangeLog | 6 ++++++ test/ruby/test_proc.rb | 16 ++++++++++++++++ vm_insnhelper.c | 2 +- 3 files changed, 23 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index 14c3c5bff5..ed328df4e4 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +Fri Dec 28 11:50:42 2012 Nobuyoshi Nakada + + * vm_insnhelper.c (vm_yield_setup_block_args): pass single argument to + single optional parameter unchanged without splatting. [Bug #7621] + [ruby-dev:46801] + Fri Dec 28 11:17:47 2012 Shugo Maeda * proc.c (method_eq): fix the documentation to refer to owner. diff --git a/test/ruby/test_proc.rb b/test/ruby/test_proc.rb index 8d84d2d60d..f9a0beecd1 100644 --- a/test/ruby/test_proc.rb +++ b/test/ruby/test_proc.rb @@ -499,6 +499,22 @@ class TestProc < Test::Unit::TestCase assert_equal [1, 2, 3], pr.call([1,2,3,4,5,6]) end + def test_proc_args_opt_signle + bug7621 = '[ruby-dev:46801]' + pr = proc {|a=:a| + a + } + assert_equal :a, pr.call() + assert_equal 1, pr.call(1) + assert_equal 1, pr.call(1,2) + + assert_equal [], pr.call([]), bug7621 + assert_equal [1], pr.call([1]), bug7621 + assert_equal [1, 2], pr.call([1,2]), bug7621 + assert_equal [1, 2, 3], pr.call([1,2,3]), bug7621 + assert_equal [1, 2, 3, 4], pr.call([1,2,3,4]), bug7621 + end + def test_proc_args_pos_opt_post pr = proc {|a,b,c=:c,d,e| [a,b,c,d,e] diff --git a/vm_insnhelper.c b/vm_insnhelper.c index c65135adab..ad21b99e56 100644 --- a/vm_insnhelper.c +++ b/vm_insnhelper.c @@ -2092,7 +2092,7 @@ vm_yield_setup_block_args(rb_thread_t *th, const rb_iseq_t * iseq, */ arg0 = argv[0]; if (!(iseq->arg_simple & 0x02) && /* exclude {|a|} */ - (m + iseq->arg_opts + iseq->arg_post_len) > 0 && /* this process is meaningful */ + ((m + iseq->arg_post_len) > 0 || iseq->arg_opts > 2) && /* this process is meaningful */ argc == 1 && !NIL_P(ary = rb_check_array_type(arg0))) { /* rhs is only an array */ th->mark_stack_len = argc = RARRAY_LENINT(ary); -- cgit v1.2.3