mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
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
This commit is contained in:
parent
8081826be6
commit
4ebe2d4ef0
2 changed files with 6 additions and 1 deletions
|
@ -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--;
|
||||
|
|
Loading…
Add table
Reference in a new issue