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

ruby-changes:38967

From: nobu <ko1@a...>
Date: Sun, 28 Jun 2015 12:07:55 +0900 (JST)
Subject: [ruby-changes:38967] nobu:r51048 (trunk): class.c: TypeError when superclass mismatch

nobu	2015-06-28 12:07:37 +0900 (Sun, 28 Jun 2015)

  New Revision: 51048

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

  Log:
    class.c: TypeError when superclass mismatch
    
    * class.c (rb_define_class_id_under): raise TypeError exception
      same as ruby level class definition when superclass mismatch.

  Modified files:
    trunk/ChangeLog
    trunk/NEWS
    trunk/class.c
    trunk/test/ruby/test_require.rb
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 51047)
+++ ChangeLog	(revision 51048)
@@ -1,3 +1,8 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Sun Jun 28 12:07:35 2015  Nobuyoshi Nakada  <nobu@r...>
+
+	* class.c (rb_define_class_id_under): raise TypeError exception
+	  same as ruby level class definition when superclass mismatch.
+
 Sun Jun 14 19:02:03 2015  Benoit Daloze  <eregontp@g...>
 
 	* lib/net/ftp.rb (makeport): close the TCPServer
Index: class.c
===================================================================
--- class.c	(revision 51047)
+++ class.c	(revision 51048)
@@ -703,7 +703,8 @@ rb_define_class_id_under(VALUE outer, ID https://github.com/ruby/ruby/blob/trunk/class.c#L703
 	    rb_raise(rb_eTypeError, "%"PRIsVALUE" is not a class", rb_id2str(id));
 	}
 	if (rb_class_real(RCLASS_SUPER(klass)) != super) {
-	    rb_name_error(id, "%"PRIsVALUE" is already defined", rb_id2str(id));
+	    rb_raise(rb_eTypeError, "superclass mismatch for class %"PRIsVALUE"",
+		     rb_id2str(id));
 	}
 	return klass;
     }
Index: NEWS
===================================================================
--- NEWS	(revision 51047)
+++ NEWS	(revision 51048)
@@ -143,6 +143,10 @@ with all sufficient information, see the https://github.com/ruby/ruby/blob/trunk/NEWS#L143
 
 === C API updates
 
+* rb_define_class_id_under() now raises a TypeError exception when the
+  class is already defined but its superclass does not match the given
+  superclass, as well as definitions in ruby level.
+
 === Build system updates
 
 === Implementation changes
Index: test/ruby/test_require.rb
===================================================================
--- test/ruby/test_require.rb	(revision 51047)
+++ test/ruby/test_require.rb	(revision 51048)
@@ -228,7 +228,7 @@ class TestRequire < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_require.rb#L228
     assert_separately([], <<-INPUT)
       module Zlib; end
       class Zlib::Error; end
-      assert_raise(NameError) do
+      assert_raise(TypeError) do
         require 'zlib'
       end
     INPUT

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

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