[前][次][番号順一覧][スレッド一覧]

ruby-changes:44908

From: nobu <ko1@a...>
Date: Sun, 4 Dec 2016 17:50:34 +0900 (JST)
Subject: [ruby-changes:44908] nobu:r56981 (trunk): class.c: missing unknown_keyword_error

nobu	2016-12-04 17:50:29 +0900 (Sun, 04 Dec 2016)

  New Revision: 56981

  https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=56981

  Log:
    class.c: missing unknown_keyword_error
    
    * class.c (rb_get_kwargs): when values are stored, corresponding
      keys have been remove from the keyword hash, and the hash should
      be empty in that case.  [ruby-dev:49893] [Bug #13004]

  Modified files:
    trunk/class.c
    trunk/test/ruby/test_keyword.rb
Index: class.c
===================================================================
--- class.c	(revision 56980)
+++ class.c	(revision 56981)
@@ -1896,7 +1896,7 @@ rb_get_kwargs(VALUE keyword_hash, const https://github.com/ruby/ruby/blob/trunk/class.c#L1896
 	}
     }
     if (!rest && keyword_hash) {
-	if (RHASH_SIZE(keyword_hash) > (unsigned int)j) {
+	if (RHASH_SIZE(keyword_hash) > (unsigned int)(values ? 0 : j)) {
 	    unknown_keyword_error(keyword_hash, table, required+optional);
 	}
     }
Index: test/ruby/test_keyword.rb
===================================================================
--- test/ruby/test_keyword.rb	(revision 56980)
+++ test/ruby/test_keyword.rb	(revision 56981)
@@ -546,6 +546,13 @@ class TestKeywordArguments < Test::Unit: https://github.com/ruby/ruby/blob/trunk/test/ruby/test_keyword.rb#L546
     }
   end
 
+  def test_unknown_keyword
+    bug13004 = '[ruby-dev:49893] [Bug #13004]'
+    assert_raise_with_message(ArgumentError, /unknown keyword: invalid-argument/, bug13004) {
+      [].sample(random: nil, "invalid-argument": nil)
+    }
+  end
+
   def test_super_with_anon_restkeywords
     bug10659 = '[ruby-core:67157] [Bug #10659]'
 

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]