ruby-changes:29011
From: nagachika <ko1@a...>
Date: Tue, 4 Jun 2013 23:30:40 +0900 (JST)
Subject: [ruby-changes:29011] nagachika:r41063 (ruby_2_0_0): merge revision(s) 40992: [Backport #8040]
nagachika 2013-06-04 23:30:28 +0900 (Tue, 04 Jun 2013) New Revision: 41063 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=41063 Log: merge revision(s) 40992: [Backport #8040] * 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. Modified directories: branches/ruby_2_0_0/ Modified files: branches/ruby_2_0_0/ChangeLog branches/ruby_2_0_0/test/ruby/test_keyword.rb branches/ruby_2_0_0/version.h branches/ruby_2_0_0/vm_insnhelper.c Index: ruby_2_0_0/ChangeLog =================================================================== --- ruby_2_0_0/ChangeLog (revision 41062) +++ ruby_2_0_0/ChangeLog (revision 41063) @@ -1,3 +1,12 @@ https://github.com/ruby/ruby/blob/trunk/ruby_2_0_0/ChangeLog#L1 +Tue Jun 4 23:27:24 2013 Yusuke Endoh <mame@t...> + + * 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. + Tue Jun 4 00:46:05 2013 Nobuyoshi Nakada <nobu@r...> * win32/win32.c (setup_overlapped, finish_overlapped): extract from Index: ruby_2_0_0/version.h =================================================================== --- ruby_2_0_0/version.h (revision 41062) +++ ruby_2_0_0/version.h (revision 41063) @@ -1,6 +1,6 @@ https://github.com/ruby/ruby/blob/trunk/ruby_2_0_0/version.h#L1 #define RUBY_VERSION "2.0.0" #define RUBY_RELEASE_DATE "2013-06-04" -#define RUBY_PATCHLEVEL 201 +#define RUBY_PATCHLEVEL 202 #define RUBY_RELEASE_YEAR 2013 #define RUBY_RELEASE_MONTH 6 Index: ruby_2_0_0/vm_insnhelper.c =================================================================== --- ruby_2_0_0/vm_insnhelper.c (revision 41062) +++ ruby_2_0_0/vm_insnhelper.c (revision 41063) @@ -1091,12 +1091,12 @@ extract_keywords(VALUE *orighash) https://github.com/ruby/ruby/blob/trunk/ruby_2_0_0/vm_insnhelper.c#L1091 } 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) { @@ -1140,7 +1140,7 @@ vm_callee_setup_arg_complex(rb_thread_t https://github.com/ruby/ruby/blob/trunk/ruby_2_0_0/vm_insnhelper.c#L1140 /* 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 */ @@ -2168,7 +2168,7 @@ vm_yield_setup_block_args(rb_thread_t *t https://github.com/ruby/ruby/blob/trunk/ruby_2_0_0/vm_insnhelper.c#L2168 /* 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); } /* Index: ruby_2_0_0/test/ruby/test_keyword.rb =================================================================== --- ruby_2_0_0/test/ruby/test_keyword.rb (revision 41062) +++ ruby_2_0_0/test/ruby/test_keyword.rb (revision 41063) @@ -22,7 +22,6 @@ class TestKeywordArguments < Test::Unit: https://github.com/ruby/ruby/blob/trunk/ruby_2_0_0/test/ruby/test_keyword.rb#L22 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 @@ -342,4 +341,15 @@ class TestKeywordArguments < Test::Unit: https://github.com/ruby/ruby/blob/trunk/ruby_2_0_0/test/ruby/test_keyword.rb#L341 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 Property changes on: ruby_2_0_0 ___________________________________________________________________ Modified: svn:mergeinfo Merged /trunk:r40992 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/