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

ruby-changes:42896

From: eregon <ko1@a...>
Date: Tue, 10 May 2016 20:50:08 +0900 (JST)
Subject: [ruby-changes:42896] eregon:r54970 (trunk): * insns.def (defineclass): Also raise an error when redeclaring the

eregon	2016-05-10 21:46:43 +0900 (Tue, 10 May 2016)

  New Revision: 54970

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

  Log:
    * insns.def (defineclass): Also raise an error when redeclaring the
      superclass of a class as Object and it has another superclass.
      [Bug #12367] [ruby-core:75446]
    * test/ruby/test_class.rb: test for above.

  Modified files:
    trunk/ChangeLog
    trunk/insns.def
    trunk/test/ruby/test_class.rb
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 54969)
+++ ChangeLog	(revision 54970)
@@ -1,3 +1,11 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Tue May 10 21:05:45 2016  Benoit Daloze  <eregontp@g...>
+
+	* insns.def (defineclass): Also raise an error when redeclaring the
+	  superclass of a class as Object and it has another superclass.
+	  [Bug #12367] [ruby-core:75446]
+
+	* test/ruby/test_class.rb: test for above.
+
 Tue May 10 14:57:09 2016  Nobuyoshi Nakada  <nobu@r...>
 
 	* random.c (obj_random_bytes): base on bytes method instead of
Index: insns.def
===================================================================
--- insns.def	(revision 54969)
+++ insns.def	(revision 54970)
@@ -865,10 +865,6 @@ defineclass https://github.com/ruby/ruby/blob/trunk/insns.def#L865
 		     rb_obj_class(super));
 	}
 
-	if (super == Qnil) {
-	    super = rb_cObject;
-	}
-
 	vm_check_if_namespace(cbase);
 
 	/* find klass */
@@ -881,7 +877,7 @@ defineclass https://github.com/ruby/ruby/blob/trunk/insns.def#L877
 		rb_raise(rb_eTypeError, "%"PRIsVALUE" is not a class", rb_id2str(id));
 	    }
 
-	    if (super != rb_cObject) {
+	    if (VM_DEFINECLASS_HAS_SUPERCLASS_P(flags)) {
 		VALUE tmp;
 		tmp = rb_class_real(RCLASS_SUPER(klass));
 
@@ -892,6 +888,9 @@ defineclass https://github.com/ruby/ruby/blob/trunk/insns.def#L888
 	    }
 	}
 	else {
+	    if (!VM_DEFINECLASS_HAS_SUPERCLASS_P(flags)) {
+		super = rb_cObject;
+	    }
 	    /* new class declaration */
 	    klass = rb_define_class_id(id, super);
 	    rb_set_class_path_string(klass, cbase, rb_id2str(id));
Index: test/ruby/test_class.rb
===================================================================
--- test/ruby/test_class.rb	(revision 54969)
+++ test/ruby/test_class.rb	(revision 54970)
@@ -378,6 +378,25 @@ class TestClass < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_class.rb#L378
     }
   end
 
+  define_method :test_invalid_reset_superclass do
+    class A; end
+    class SuperclassCannotBeReset < A
+    end
+    assert_equal A, SuperclassCannotBeReset.superclass
+
+    assert_raise_with_message(TypeError, /superclass mismatch/) {
+      class SuperclassCannotBeReset < String
+      end
+    }
+
+    assert_raise_with_message(TypeError, /superclass mismatch/, "[ruby-core:75446]") {
+      class SuperclassCannotBeReset < Object
+      end
+    }
+
+    assert_equal A, SuperclassCannotBeReset.superclass
+  end
+
   def test_cloned_singleton_method_added
     bug5283 = '[ruby-dev:44477]'
     added = []

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

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