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

ruby-changes:28968

From: nobu <ko1@a...>
Date: Sat, 1 Jun 2013 17:21:55 +0900 (JST)
Subject: [ruby-changes:28968] nobu:r41020 (trunk): vm_insnhelper.c: extract keyword arguments after splat

nobu	2013-06-01 17:21:39 +0900 (Sat, 01 Jun 2013)

  New Revision: 41020

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

  Log:
    vm_insnhelper.c: extract keyword arguments after splat
    
    * vm_insnhelper.c (vm_yield_setup_block_args): split single parameter
      if any keyword arguments exist, and then extract keyword arguments.
      [ruby-core:55203] [Bug #8463]

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

Index: ChangeLog
===================================================================
--- ChangeLog	(revision 41019)
+++ ChangeLog	(revision 41020)
@@ -1,3 +1,9 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Sat Jun  1 17:21:24 2013  Nobuyoshi Nakada  <nobu@r...>
+
+	* vm_insnhelper.c (vm_yield_setup_block_args): split single parameter
+	  if any keyword arguments exist, and then extract keyword arguments.
+	  [ruby-core:55203] [Bug #8463]
+
 Sat Jun  1 11:16:22 2013  Nobuyoshi Nakada  <nobu@r...>
 
 	* error.c (rb_exc_new_cstr): rename from rb_exc_new2.
Index: vm_insnhelper.c
===================================================================
--- vm_insnhelper.c	(revision 41019)
+++ vm_insnhelper.c	(revision 41020)
@@ -2193,11 +2193,6 @@ vm_yield_setup_block_args(rb_thread_t *t https://github.com/ruby/ruby/blob/trunk/vm_insnhelper.c#L2193
 
     th->mark_stack_len = argc;
 
-    /* keyword argument */
-    if (iseq->arg_keyword != -1) {
-	argc = vm_callee_setup_keyword_arg(iseq, argc, m, argv, &keyword_hash);
-    }
-
     /*
      * yield [1, 2]
      *  => {|a|} => a = [1, 2]
@@ -2207,6 +2202,7 @@ vm_yield_setup_block_args(rb_thread_t *t https://github.com/ruby/ruby/blob/trunk/vm_insnhelper.c#L2202
     if (!(iseq->arg_simple & 0x02) &&                           /* exclude {|a|} */
 	((m + iseq->arg_post_len) > 0 ||			/* positional arguments exist */
 	 iseq->arg_opts > 2 ||					/* multiple optional arguments exist */
+	 iseq->arg_keyword != -1 ||				/* any keyword arguments */
 	 0) &&
 	argc == 1 && !NIL_P(ary = rb_check_array_type(arg0))) { /* rhs is only an array */
 	th->mark_stack_len = argc = RARRAY_LENINT(ary);
@@ -2216,6 +2212,11 @@ vm_yield_setup_block_args(rb_thread_t *t https://github.com/ruby/ruby/blob/trunk/vm_insnhelper.c#L2212
 	MEMCPY(argv, RARRAY_PTR(ary), VALUE, argc);
     }
 
+    /* keyword argument */
+    if (iseq->arg_keyword != -1) {
+	argc = vm_callee_setup_keyword_arg(iseq, argc, m, argv, &keyword_hash);
+    }
+
     for (i=argc; i<m; i++) {
 	argv[i] = Qnil;
     }
Index: test/ruby/test_keyword.rb
===================================================================
--- test/ruby/test_keyword.rb	(revision 41019)
+++ test/ruby/test_keyword.rb	(revision 41020)
@@ -263,9 +263,14 @@ class TestKeywordArguments < Test::Unit: https://github.com/ruby/ruby/blob/trunk/test/ruby/test_keyword.rb#L263
 
   def test_rest_keyrest
     bug7665 = '[ruby-core:51278]'
+    bug8463 = '[ruby-core:55203] [Bug #8463]'
     expect = [*%w[foo bar], {zzz: 42}]
     assert_equal(expect, rest_keyrest(*expect), bug7665)
-    assert_equal(expect, proc {|*args, **opt| next *args, opt}.call(*expect), bug7665)
+    pr = proc {|*args, **opt| next *args, opt}
+    assert_equal(expect, pr.call(*expect), bug7665)
+    assert_equal(expect, pr.call(expect), bug8463)
+    pr = proc {|a, *b, **opt| next a, *b, opt}
+    assert_equal(expect, pr.call(expect), bug8463)
   end
 
   def test_bare_kwrest

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

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