From 79f7dfabb69ec435b6b0be5ccb5157cb85e71580 Mon Sep 17 00:00:00 2001 From: nobu Date: Thu, 21 Mar 2013 19:51:19 +0000 Subject: vm_insnhelper.c: check required kwarg with resthash * vm_insnhelper.c (vm_callee_setup_keyword_arg): should check required keyword arguments even if rest hash is defined. [ruby-core:53608] [Bug #8139] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@39869 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- test/ruby/test_keyword.rb | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'test/ruby/test_keyword.rb') diff --git a/test/ruby/test_keyword.rb b/test/ruby/test_keyword.rb index b7b4301ca1..dc20c6d7fd 100644 --- a/test/ruby/test_keyword.rb +++ b/test/ruby/test_keyword.rb @@ -296,10 +296,17 @@ class TestKeywordArguments < Test::Unit::TestCase o = Object.new assert_nothing_raised(SyntaxError, feature7701) do eval("def o.foo(a:) a; end") + eval("def o.bar(a:,**b) [a, b]; end") end assert_raise(ArgumentError, feature7701) {o.foo} assert_equal(42, o.foo(a: 42), feature7701) assert_equal([[:keyreq, :a]], o.method(:foo).parameters, feature7701) + + bug8139 = '[ruby-core:53608] [Bug #8139] required keyword argument with rest hash' + assert_equal([42, {}], o.bar(a: 42), feature7701) + assert_equal([[:keyreq, :a], [:keyrest, :b]], o.method(:bar).parameters, feature7701) + assert_raise(ArgumentError, bug8139) {o.bar(c: bug8139)} + assert_raise(ArgumentError, bug8139) {o.bar} end def test_block_required_keyword @@ -310,5 +317,14 @@ class TestKeywordArguments < Test::Unit::TestCase assert_raise(ArgumentError, feature7701) {b.call} assert_equal(42, b.call(a: 42), feature7701) assert_equal([[:keyreq, :a]], b.parameters, feature7701) + + bug8139 = '[ruby-core:53608] [Bug #8139] required keyword argument with rest hash' + b = assert_nothing_raised(SyntaxError, feature7701) do + break eval("proc {|a:, **b| [a, b]}") + end + assert_equal([42, {}], b.call(a: 42), feature7701) + assert_equal([[:keyreq, :a], [:keyrest, :b]], b.parameters, feature7701) + assert_raise(ArgumentError, bug8139) {b.call(c: bug8139)} + assert_raise(ArgumentError, bug8139) {b.call} end end -- cgit v1.2.3