summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2013-06-01 08:21:39 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2013-06-01 08:21:39 +0000
commit06c7ede25923582b7f61c85920cd195b3c0447ce (patch)
tree93c5ca55a6cc67a2d8c1e97df001589fdd114aee
parent767c502252daf751a2efbd0acc5766cd5492e9fb (diff)
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
-rw-r--r--ChangeLog6
-rw-r--r--test/ruby/test_keyword.rb7
-rw-r--r--vm_insnhelper.c11
3 files changed, 18 insertions, 6 deletions
diff --git a/ChangeLog b/ChangeLog
index 6578b966e5..82ca655403 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -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.
diff --git a/test/ruby/test_keyword.rb b/test/ruby/test_keyword.rb
index ed1f79cfd3..4ff7c40321 100644
--- a/test/ruby/test_keyword.rb
+++ b/test/ruby/test_keyword.rb
@@ -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
diff --git a/vm_insnhelper.c b/vm_insnhelper.c
index b519670370..5a3a14d5ac 100644
--- a/vm_insnhelper.c
+++ b/vm_insnhelper.c
@@ -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;
}