Skip to content

Commit 72d1a79

Browse files
committed
[Bug #19833] Fix index underflow at superclasses of BasicObject
1 parent 6929267 commit 72d1a79

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

object.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2165,6 +2165,10 @@ rb_class_superclass(VALUE klass)
21652165
if (klass == rb_cBasicObject) return Qnil;
21662166
rb_raise(rb_eTypeError, "uninitialized class");
21672167
}
2168+
2169+
if (!RCLASS_SUPERCLASS_DEPTH(klass)) {
2170+
return Qnil;
2171+
}
21682172
else {
21692173
super = RCLASS_SUPERCLASSES(klass)[RCLASS_SUPERCLASS_DEPTH(klass) - 1];
21702174
RUBY_ASSERT(RB_TYPE_P(klass, T_CLASS));

test/ruby/test_class.rb

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,13 @@ def test_instantiate_singleton_class
9696

9797
def test_superclass_of_basicobject
9898
assert_equal(nil, BasicObject.superclass)
99+
100+
assert_separately([], "#{<<~"begin;"}\n#{<<~'end;'}")
101+
begin;
102+
module Mod end
103+
BasicObject.include(Mod)
104+
assert_equal(nil, BasicObject.superclass)
105+
end;
99106
end
100107

101108
def test_module_function

0 commit comments

Comments
 (0)