From 91afce9afa0033bf9835e70207306f3715fd69f7 Mon Sep 17 00:00:00 2001 From: nobu Date: Sat, 14 Dec 2013 08:39:17 +0000 Subject: vm_insnhelper.c: post arguments as mandatory * vm_insnhelper.c (vm_callee_setup_arg_complex): count post arguments as mandatory arguments. [ruby-core:57706] [Bug #8993] * vm_insnhelper.c (vm_yield_setup_block_args): ditto. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@44207 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ChangeLog | 7 +++++++ test/ruby/test_keyword.rb | 10 ++++++++++ vm_insnhelper.c | 7 ++++--- 3 files changed, 21 insertions(+), 3 deletions(-) diff --git a/ChangeLog b/ChangeLog index eb02a49c12..d7c08e4d10 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +Sat Dec 14 17:39:00 2013 Nobuyoshi Nakada + + * vm_insnhelper.c (vm_callee_setup_arg_complex): count post + arguments as mandatory arguments. [ruby-core:57706] [Bug #8993] + + * vm_insnhelper.c (vm_yield_setup_block_args): ditto. + Sat Dec 14 16:26:46 2013 Nobuyoshi Nakada * configure.in (rubylibprefix): replace exec_prefix as well as diff --git a/test/ruby/test_keyword.rb b/test/ruby/test_keyword.rb index e7e1a927e6..7e708454ae 100644 --- a/test/ruby/test_keyword.rb +++ b/test/ruby/test_keyword.rb @@ -401,6 +401,16 @@ class TestKeywordArguments < Test::Unit::TestCase assert_equal([{}, {:bar=>"x"}], a.new.foo({}, bar: "x")) end + def test_precedence_of_keyword_arguments_with_post_argument + bug8993 = '[ruby-core:57706] [Bug #8993]' + a = Class.new do + def foo(a, b, c=1, *d, e, f:2, **g) + [a, b, c, d, e, f, g] + end + end + assert_equal([1, 2, 1, [], {:f=>5}, 2, {}], a.new.foo(1, 2, f:5), bug8993) + end + def test_gced_object_in_stack bug8964 = '[ruby-dev:47729] [Bug #8964]' assert_normal_exit %q{ diff --git a/vm_insnhelper.c b/vm_insnhelper.c index 6174e13a58..08915c8b96 100644 --- a/vm_insnhelper.c +++ b/vm_insnhelper.c @@ -1109,7 +1109,7 @@ vm_callee_setup_arg_complex(rb_thread_t *th, rb_call_info_t *ci, const rb_iseq_t /* keyword argument */ if (iseq->arg_keyword != -1) { - argc = vm_callee_setup_keyword_arg(iseq, argc, m, orig_argv, &keyword_hash); + argc = vm_callee_setup_keyword_arg(iseq, argc, min, orig_argv, &keyword_hash); } /* mandatory */ @@ -2164,6 +2164,7 @@ vm_yield_setup_block_args(rb_thread_t *th, const rb_iseq_t * iseq, int i; int argc = orig_argc; const int m = iseq->argc; + const int min = m + iseq->arg_post_len; VALUE ary, arg0; VALUE keyword_hash = Qnil; int opt_pc = 0; @@ -2177,7 +2178,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_post_len) > 0 || /* positional arguments exist */ + (min > 0 || /* positional arguments exist */ iseq->arg_opts > 2 || /* multiple optional arguments exist */ iseq->arg_keyword != -1 || /* any keyword arguments */ 0) && @@ -2200,7 +2201,7 @@ vm_yield_setup_block_args(rb_thread_t *th, const rb_iseq_t * iseq, /* keyword argument */ if (iseq->arg_keyword != -1) { - argc = vm_callee_setup_keyword_arg(iseq, argc, m, argv, &keyword_hash); + argc = vm_callee_setup_keyword_arg(iseq, argc, min, argv, &keyword_hash); } for (i=argc; i