summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog8
-rw-r--r--insns.def9
-rw-r--r--test/ruby/test_class.rb19
-rw-r--r--version.h2
4 files changed, 32 insertions, 6 deletions
diff --git a/ChangeLog b/ChangeLog
index a266ab0c8e..8aa48f1441 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+Fri Jun 10 15:54:05 2016 Benoit Daloze <eregontp@gmail.com>
+
+ * 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.
+
Fri Jun 10 15:46:24 2016 Kazuhiro NISHIYAMA <zn@mbf.nifty.com>
* bignum.c: [DOC] Update result of 123456789 ** -2.
diff --git a/insns.def b/insns.def
index eb1ffeb62e..834f3dd691 100644
--- a/insns.def
+++ b/insns.def
@@ -925,10 +925,6 @@ defineclass
rb_obj_classname(super));
}
- if (super == Qnil) {
- super = rb_cObject;
- }
-
vm_check_if_namespace(cbase);
/* find klass */
@@ -941,7 +937,7 @@ defineclass
rb_raise(rb_eTypeError, "%s is not a class", rb_id2name(id));
}
- if (super != rb_cObject) {
+ if (VM_DEFINECLASS_HAS_SUPERCLASS_P(flags)) {
VALUE tmp;
tmp = rb_class_real(RCLASS_SUPER(klass));
@@ -952,6 +948,9 @@ defineclass
}
}
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));
diff --git a/test/ruby/test_class.rb b/test/ruby/test_class.rb
index e17f56f913..e02a3d243d 100644
--- a/test/ruby/test_class.rb
+++ b/test/ruby/test_class.rb
@@ -358,6 +358,25 @@ class TestClass < Test::Unit::TestCase
end
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 = []
diff --git a/version.h b/version.h
index eb2b6374b5..15720cdd1c 100644
--- a/version.h
+++ b/version.h
@@ -1,6 +1,6 @@
#define RUBY_VERSION "2.2.6"
#define RUBY_RELEASE_DATE "2016-06-10"
-#define RUBY_PATCHLEVEL 326
+#define RUBY_PATCHLEVEL 327
#define RUBY_RELEASE_YEAR 2016
#define RUBY_RELEASE_MONTH 6