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

ruby-changes:44833

From: nobu <ko1@a...>
Date: Sun, 27 Nov 2016 20:07:33 +0900 (JST)
Subject: [ruby-changes:44833] nobu:r56906 (trunk): object.c: no TypeError at special const dup

nobu	2016-11-27 20:07:27 +0900 (Sun, 27 Nov 2016)

  New Revision: 56906

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

  Log:
    object.c: no TypeError at special const dup
    
    * object.c (rb_obj_dup): no longer raise a TypeError for special
      constants, and return itself instead.  [Feature#12979]

  Modified files:
    trunk/object.c
    trunk/test/ruby/test_object.rb
    trunk/test/rubygems/test_gem_specification.rb
Index: object.c
===================================================================
--- object.c	(revision 56905)
+++ object.c	(revision 56906)
@@ -423,7 +423,7 @@ rb_obj_dup(VALUE obj) https://github.com/ruby/ruby/blob/trunk/object.c#L423
     VALUE dup;
 
     if (rb_special_const_p(obj)) {
-        rb_raise(rb_eTypeError, "can't dup %s", rb_obj_classname(obj));
+	return obj;
     }
     dup = rb_obj_alloc(rb_obj_class(obj));
     init_copy(dup, obj);
Index: test/ruby/test_object.rb
===================================================================
--- test/ruby/test_object.rb	(revision 56905)
+++ test/ruby/test_object.rb	(revision 56906)
@@ -19,9 +19,9 @@ class TestObject < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_object.rb#L19
   end
 
   def test_dup
-    assert_raise(TypeError) { 1.dup }
-    assert_raise(TypeError) { true.dup }
-    assert_raise(TypeError) { nil.dup }
+    assert_equal 1, 1.dup
+    assert_equal true, true.dup
+    assert_equal nil, nil.dup
 
     assert_raise(TypeError) do
       Object.new.instance_eval { initialize_copy(1) }
Index: test/rubygems/test_gem_specification.rb
===================================================================
--- test/rubygems/test_gem_specification.rb	(revision 56905)
+++ test/rubygems/test_gem_specification.rb	(revision 56906)
@@ -1260,7 +1260,7 @@ dependencies: [] https://github.com/ruby/ruby/blob/trunk/test/rubygems/test_gem_specification.rb#L1260
       s.version = '1'
     end
 
-    spec.instance_variable_set :@licenses, :blah
+    spec.instance_variable_set :@licenses, Object.new.singleton_class
     spec.loaded_from = '/path/to/file'
 
     e = assert_raises Gem::FormatException do

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

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