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

ruby-changes:49935

From: nobu <ko1@a...>
Date: Fri, 26 Jan 2018 15:41:19 +0900 (JST)
Subject: [ruby-changes:49935] nobu:r62053 (trunk): error.c: KeyError missing keyword arguments

nobu	2018-01-26 15:41:13 +0900 (Fri, 26 Jan 2018)

  New Revision: 62053

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

  Log:
    error.c: KeyError missing keyword arguments
    
    * error.c (key_err_initialize): leave attributes for missing
      keyword arguments unset, so accessors can tell if it is missing
      or explicit nil.  [Feature #14313]

  Modified files:
    trunk/error.c
    trunk/test/ruby/test_key_error.rb
Index: error.c
===================================================================
--- error.c	(revision 62052)
+++ error.c	(revision 62053)
@@ -1692,8 +1692,6 @@ key_err_initialize(int argc, VALUE *argv https://github.com/ruby/ruby/blob/trunk/error.c#L1692
 {
     VALUE message;
     VALUE options;
-    VALUE receiver = Qnil;
-    VALUE key = Qnil;
 
     rb_scan_args(argc, argv, "01:", &message, &options);
 
@@ -1711,16 +1709,13 @@ key_err_initialize(int argc, VALUE *argv https://github.com/ruby/ruby/blob/trunk/error.c#L1709
 	keywords[1] = id_key;
 	rb_get_kwargs(options, keywords, 0, 2, values);
 	if (values[0] != Qundef) {
-	    receiver = values[0];
+	    rb_ivar_set(self, id_receiver, values[0]);
 	}
 	if (values[1] != Qundef) {
-	    key = values[1];
+	    rb_ivar_set(self, id_key, values[1]);
 	}
     }
 
-    rb_ivar_set(self, id_receiver, receiver);
-    rb_ivar_set(self, id_key, key);
-
     return self;
 }
 
Index: test/ruby/test_key_error.rb
===================================================================
--- test/ruby/test_key_error.rb	(revision 62052)
+++ test/ruby/test_key_error.rb	(revision 62053)
@@ -15,11 +15,15 @@ class TestKeyError < Test::Unit::TestCas https://github.com/ruby/ruby/blob/trunk/test/ruby/test_key_error.rb#L15
     receiver = Object.new
     error = KeyError.new(receiver: receiver)
     assert_equal(receiver, error.receiver)
+    error = KeyError.new
+    assert_raise(ArgumentError) {error.receiver}
   end
 
   def test_key
     error = KeyError.new(key: :key)
     assert_equal(:key, error.key)
+    error = KeyError.new
+    assert_raise(ArgumentError) {error.key}
   end
 
   def test_receiver_and_key

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

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