diff --git a/test/ruby/test_keyword.rb b/test/ruby/test_keyword.rb index c7dd6c88e3..b673cb7eec 100644 --- a/test/ruby/test_keyword.rb +++ b/test/ruby/test_keyword.rb @@ -506,12 +506,16 @@ class TestKeywordArguments < Test::Unit::TestCase def test_splat_hash m = Object.new def m.f() :ok; end + def m.f2(a = nil) a; end o = {a: 1} assert_raise_with_message(ArgumentError, /unknown keyword: a/) { m.f(**o) } o = {} assert_equal(:ok, m.f(**o), '[ruby-core:68124] [Bug #10856]') + + o = {a: 42} + assert_equal({a: 42}, m.f2(**o), '[ruby-core:82280] [Bug #13791]') end def test_gced_object_in_stack diff --git a/vm_args.c b/vm_args.c index b505292e68..39f511998d 100644 --- a/vm_args.c +++ b/vm_args.c @@ -616,7 +616,8 @@ setup_parameters_complex(rb_thread_t * const th, const rb_iseq_t * const iseq, if (given_argc > min_argc && (iseq->body->param.flags.has_kw || iseq->body->param.flags.has_kwrest || - (!iseq->body->param.flags.has_rest && (ci->flag & VM_CALL_KW_SPLAT))) && + (!iseq->body->param.flags.has_rest && given_argc > max_argc && + (ci->flag & VM_CALL_KW_SPLAT))) && args->kw_argv == NULL) { if (args_pop_keyword_hash(args, &keyword_hash, th)) { given_argc--;