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]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@41020 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
nobu 2013-06-01 08:21:39 +00:00
parent 767c502252
commit 06c7ede259
3 changed files with 18 additions and 6 deletions

View File

@ -1,3 +1,9 @@
Sat Jun 1 17:21:24 2013 Nobuyoshi Nakada <nobu@ruby-lang.org>
* 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@ruby-lang.org>
* error.c (rb_exc_new_cstr): rename from rb_exc_new2.

View File

@ -263,9 +263,14 @@ class TestKeywordArguments < Test::Unit::TestCase
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

View File

@ -2193,11 +2193,6 @@ vm_yield_setup_block_args(rb_thread_t *th, const rb_iseq_t * iseq,
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 *th, const rb_iseq_t * iseq,
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 *th, const rb_iseq_t * iseq,
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;
}