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

ruby-changes:25564

From: nobu <ko1@a...>
Date: Sun, 11 Nov 2012 15:39:22 +0900 (JST)
Subject: [ruby-changes:25564] nobu:r37621 (trunk): hash.c: warn for wrong elements

nobu	2012-11-11 15:39:08 +0900 (Sun, 11 Nov 2012)

  New Revision: 37621

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

  Log:
    hash.c: warn for wrong elements
    
    * hash.c (rb_hash_s_create): just warn for wrong elements now.
      [ruby-dev:46440] [Bug #7300]

  Modified files:
    trunk/ChangeLog
    trunk/hash.c
    trunk/test/ruby/test_hash.rb

Index: ChangeLog
===================================================================
--- ChangeLog	(revision 37620)
+++ ChangeLog	(revision 37621)
@@ -1,5 +1,8 @@
-Sun Nov 11 15:38:14 2012  Nobuyoshi Nakada  <nobu@r...>
+Sun Nov 11 15:39:04 2012  Nobuyoshi Nakada  <nobu@r...>
 
+	* hash.c (rb_hash_s_create): just warn for wrong elements now.
+	  [ruby-dev:46440] [Bug #7300]
+
 	* hash.c (rb_hash_s_create): refine error messages.
 
 	* error.c (rb_builtin_class_name): share for above.
@@ -28,7 +31,7 @@
 	* vm_core.h (rb_call_info_t::refinements), compile.c (new_callinfo):
 	  add a new field for inline method cache.
 
-	* vm_insnhelper.c (vm_search_method): check rb_call_info_t::refinements 
+	* vm_insnhelper.c (vm_search_method): check rb_call_info_t::refinements
 	  not to confuse inline method cache when module_eval is used with
 	  refinements.
 
Index: hash.c
===================================================================
--- hash.c	(revision 37620)
+++ hash.c	(revision 37621)
@@ -398,9 +398,17 @@
 		VALUE key, val = Qnil;
 
 		if (NIL_P(v)) {
+#if 0 /* refix in the next release */
 		    rb_raise(rb_eArgError, "wrong element type %s at %ld (expected array)",
 			     rb_builtin_class_name(e), i);
 
+#else
+		    rb_warn("wrong element type %s at %ld (expected array)",
+			    rb_builtin_class_name(e), i);
+		    rb_warn("ignoring wrong elements is deprecated, remove them explicitly");
+		    rb_warn("this causes ArgumentError in the next release");
+		    continue;
+#endif
 		}
 		switch (RARRAY_LEN(v)) {
 		  default:
Index: test/ruby/test_hash.rb
===================================================================
--- test/ruby/test_hash.rb	(revision 37620)
+++ test/ruby/test_hash.rb	(revision 37621)
@@ -1,5 +1,7 @@
+# -*- coding: us-ascii -*-
 require 'test/unit'
 require 'continuation'
+require_relative 'envutil'
 
 class TestHash < Test::Unit::TestCase
 
@@ -739,8 +741,8 @@
   def test_create
     assert_equal({1=>2, 3=>4}, Hash[[[1,2],[3,4]]])
     assert_raise(ArgumentError) { Hash[0, 1, 2] }
+    assert_warning(/wrong element type Fixnum at 1 /) {Hash[[[1, 2], 3]]}
     bug5406 = '[ruby-core:39945]'
-    assert_raise(ArgumentError, bug5406) { Hash[[[1, 2], 3]] }
     assert_raise(ArgumentError, bug5406) { Hash[[[1, 2], [3, 4, 5]]] }
     assert_equal({1=>2, 3=>4}, Hash[1,2,3,4])
     o = Object.new

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

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