зеркало из https://github.com/github/ruby.git
* vm_insnhelper.c (vm_callee_setup_keyword_arg,
vm_callee_setup_arg_complex): consider a hash argument for keyword only when the number of arguments is more than the expected mandatory parameters. [ruby-core:53199] [ruby-trunk - Bug #8040] * test/ruby/test_keyword.rb: update a test for above. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@40992 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
Родитель
89a452c7c1
Коммит
6f9f8d2ef7
|
@ -1,3 +1,12 @@
|
|||
Thu May 30 19:47:42 2013 Yusuke Endoh <mame@tsg.ne.jp>
|
||||
|
||||
* vm_insnhelper.c (vm_callee_setup_keyword_arg,
|
||||
vm_callee_setup_arg_complex): consider a hash argument for keyword
|
||||
only when the number of arguments is more than the expected
|
||||
mandatory parameters. [ruby-core:53199] [ruby-trunk - Bug #8040]
|
||||
|
||||
* test/ruby/test_keyword.rb: update a test for above.
|
||||
|
||||
Thu May 30 17:55:04 2013 Zachary Scott <zachary@zacharyscott.net>
|
||||
|
||||
* process.c: RDoc on Process.spawn
|
||||
|
|
|
@ -22,7 +22,6 @@ class TestKeywordArguments < Test::Unit::TestCase
|
|||
|
||||
def test_f2
|
||||
assert_equal([:xyz, "foo", 424242], f2(:xyz))
|
||||
assert_raise(ArgumentError) { f2({}) } # [ruby-dev:46712] [Bug #7529]
|
||||
assert_equal([{"bar"=>42}, "foo", 424242], f2("bar"=>42))
|
||||
end
|
||||
|
||||
|
@ -379,4 +378,15 @@ class TestKeywordArguments < Test::Unit::TestCase
|
|||
end
|
||||
assert_equal({:bar=>"x"}, a.new.foo(bar: "x"), bug8416)
|
||||
end
|
||||
|
||||
def test_precedence_of_keyword_arguments
|
||||
bug8040 = '[ruby-core:53199] [Bug #8040]'
|
||||
a = Class.new do
|
||||
def foo(x, **h)
|
||||
[x, h]
|
||||
end
|
||||
end
|
||||
assert_equal([{}, {}], a.new.foo({}))
|
||||
assert_equal([{}, {:bar=>"x"}], a.new.foo({}, bar: "x"))
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1097,12 +1097,12 @@ extract_keywords(VALUE *orighash)
|
|||
}
|
||||
|
||||
static inline int
|
||||
vm_callee_setup_keyword_arg(const rb_iseq_t *iseq, int argc, VALUE *orig_argv, VALUE *kwd)
|
||||
vm_callee_setup_keyword_arg(const rb_iseq_t *iseq, int argc, int m, VALUE *orig_argv, VALUE *kwd)
|
||||
{
|
||||
VALUE keyword_hash, orig_hash;
|
||||
int i, j;
|
||||
|
||||
if (argc > 0 &&
|
||||
if (argc > m &&
|
||||
!NIL_P(orig_hash = rb_check_hash_type(orig_argv[argc-1])) &&
|
||||
(keyword_hash = extract_keywords(&orig_hash)) != 0) {
|
||||
if (!orig_hash) {
|
||||
|
@ -1167,7 +1167,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, orig_argv, &keyword_hash);
|
||||
argc = vm_callee_setup_keyword_arg(iseq, argc, m, orig_argv, &keyword_hash);
|
||||
}
|
||||
|
||||
/* mandatory */
|
||||
|
@ -2195,7 +2195,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, argv, &keyword_hash);
|
||||
argc = vm_callee_setup_keyword_arg(iseq, argc, m, argv, &keyword_hash);
|
||||
}
|
||||
|
||||
/*
|
||||
|
|
Загрузка…
Ссылка в новой задаче