[前][次][番号順一覧][スレッド一覧]

ruby-changes:26588

From: nobu <ko1@a...>
Date: Fri, 28 Dec 2012 11:51:14 +0900 (JST)
Subject: [ruby-changes:26588] nobu:r38639 (trunk): vm_insnhelper.c: no splat single opt arg

nobu	2012-12-28 11:50:57 +0900 (Fri, 28 Dec 2012)

  New Revision: 38639

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=38639

  Log:
    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]

  Modified files:
    trunk/ChangeLog
    trunk/test/ruby/test_proc.rb
    trunk/vm_insnhelper.c

Index: ChangeLog
===================================================================
--- ChangeLog	(revision 38638)
+++ ChangeLog	(revision 38639)
@@ -1,3 +1,9 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Fri Dec 28 11:50:42 2012  Nobuyoshi Nakada  <nobu@r...>
+
+	* 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@r...>
 
 	* proc.c (method_eq): fix the documentation to refer to owner.
Index: vm_insnhelper.c
===================================================================
--- vm_insnhelper.c	(revision 38638)
+++ vm_insnhelper.c	(revision 38639)
@@ -2092,7 +2092,7 @@ vm_yield_setup_block_args(rb_thread_t *t https://github.com/ruby/ruby/blob/trunk/vm_insnhelper.c#L2092
      */
     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);
 
Index: test/ruby/test_proc.rb
===================================================================
--- test/ruby/test_proc.rb	(revision 38638)
+++ test/ruby/test_proc.rb	(revision 38639)
@@ -499,6 +499,22 @@ class TestProc < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_proc.rb#L499
     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]

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]