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

ruby-changes:36021

From: nobu <ko1@a...>
Date: Thu, 23 Oct 2014 03:42:09 +0900 (JST)
Subject: [ruby-changes:36021] nobu:r48102 (trunk): class.c: delete expected keywords directly

nobu	2014-10-23 03:41:54 +0900 (Thu, 23 Oct 2014)

  New Revision: 48102

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

  Log:
    class.c: delete expected keywords directly
    
    * class.c (unknown_keyword_error): delete expected keywords
      directly from raw table, so that the given block is not called.
      [ruby-core:65837] [Bug #10413]

  Modified files:
    trunk/ChangeLog
    trunk/class.c
    trunk/test/ruby/test_keyword.rb
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 48101)
+++ ChangeLog	(revision 48102)
@@ -1,3 +1,9 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Thu Oct 23 03:41:51 2014  Nobuyoshi Nakada  <nobu@r...>
+
+	* class.c (unknown_keyword_error): delete expected keywords
+	  directly from raw table, so that the given block is not called.
+	  [ruby-core:65837] [Bug #10413]
+
 Thu Oct 23 02:33:01 2014  Nobuyoshi Nakada  <nobu@r...>
 
 	* common.mk (update-unicode): invert dependency to run every times.
Index: class.c
===================================================================
--- class.c	(revision 48101)
+++ class.c	(revision 48102)
@@ -1881,10 +1881,12 @@ NORETURN(static void unknown_keyword_err https://github.com/ruby/ruby/blob/trunk/class.c#L1881
 static void
 unknown_keyword_error(VALUE hash, const ID *table, int keywords)
 {
+    st_table *tbl = rb_hash_tbl_raw(hash);
     VALUE keys;
     int i;
     for (i = 0; i < keywords; i++) {
-	rb_hash_delete(hash, ID2SYM(table[i]));
+	st_data_t key = ID2SYM(table[i]);
+	st_delete(tbl, &key, NULL);
     }
     keys = rb_funcall(hash, rb_intern("keys"), 0, 0);
     if (!RB_TYPE_P(keys, T_ARRAY)) rb_raise(rb_eArgError, "unknown keyword");
Index: test/ruby/test_keyword.rb
===================================================================
--- test/ruby/test_keyword.rb	(revision 48101)
+++ test/ruby/test_keyword.rb	(revision 48102)
@@ -514,4 +514,19 @@ class TestKeywordArguments < Test::Unit: https://github.com/ruby/ruby/blob/trunk/test/ruby/test_keyword.rb#L514
       assert_nothing_raised(bug) {eval("def a(hoge:); end")}
     end;
   end
+
+  def test_unknown_keyword_with_block
+    bug10413 = '[ruby-core:65837] [Bug #10413]'
+    class << (o = Object.new)
+      def bar(k2: 'v2')
+      end
+
+      def foo
+        bar(k1: 1)
+      end
+    end
+    assert_raise_with_message(ArgumentError, /unknown keyword: k1/, bug10413) {
+      o.foo {raise "unreachable"}
+    }
+  end
 end

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

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