summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog6
-rw-r--r--test/ruby/test_proc.rb16
-rw-r--r--vm_insnhelper.c2
3 files changed, 23 insertions, 1 deletions
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 <nobu@ruby-lang.org>
+
+ * 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 <shugo@ruby-lang.org>
* 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);