diff options
author | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2017-08-10 00:32:12 +0000 |
---|---|---|
committer | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2017-08-10 00:32:12 +0000 |
commit | 4ebe2d4ef05f3c924b5e8e09035a63ada16cda64 (patch) | |
tree | e6edfb06c48b9cf9df1c559f58dc0274bf26544e | |
parent | 8081826be6a1091c311ed4793abffc2ba1194fe0 (diff) |
vm_args.c: prefer optarg to keyword splat
* vm_args.c (setup_parameters_complex): prefer optional argument
to splat keyword arguments for backward compatibility.
[ruby-core:82280] [Bug #13791]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@59554 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r-- | test/ruby/test_keyword.rb | 4 | ||||
-rw-r--r-- | vm_args.c | 3 |
2 files changed, 6 insertions, 1 deletions
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 @@ -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--; |