Skip to content

Commit

Permalink
class.c: TypeError when superclass mismatch
Browse files Browse the repository at this point in the history
* class.c (rb_define_class_id_under): raise TypeError exception
  same as ruby level class definition when superclass mismatch.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@51048 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
  • Loading branch information
nobu committed Jun 28, 2015
1 parent 6cdc55f commit a13ab23
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 2 deletions.
5 changes: 5 additions & 0 deletions ChangeLog
@@ -1,3 +1,8 @@
Sun Jun 28 12:07:35 2015 Nobuyoshi Nakada <nobu@ruby-lang.org>

* 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@gmail.com>

* lib/net/ftp.rb (makeport): close the TCPServer
Expand Down
4 changes: 4 additions & 0 deletions NEWS
Expand Up @@ -143,6 +143,10 @@ with all sufficient information, see the ChangeLog file.

=== 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
3 changes: 2 additions & 1 deletion class.c
Expand Up @@ -703,7 +703,8 @@ rb_define_class_id_under(VALUE outer, ID id, VALUE super)
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;
}
Expand Down
2 changes: 1 addition & 1 deletion test/ruby/test_require.rb
Expand Up @@ -228,7 +228,7 @@ module Zlib; end
assert_separately([], <<-INPUT)
module Zlib; end
class Zlib::Error; end
assert_raise(NameError) do
assert_raise(TypeError) do
require 'zlib'
end
INPUT
Expand Down

0 comments on commit a13ab23

Please sign in to comment.