diff options
author | Nobuyoshi Nakada <nobu@ruby-lang.org> | 2023-08-08 19:03:38 +0900 |
---|---|---|
committer | Nobuyoshi Nakada <nobu@ruby-lang.org> | 2023-08-08 19:03:38 +0900 |
commit | 72d1a790cfe0e4a457db98c587f1acaa5e39f001 (patch) | |
tree | 1c3429801afd1f8699eab29f61fe54f4695db41e | |
parent | 69292676a25a0e4bf1e80065737ad5cb42122c2a (diff) | |
download | ruby-72d1a790cfe0e4a457db98c587f1acaa5e39f001.tar.gz |
[Bug #19833] Fix index underflow at superclasses of `BasicObject`
-rw-r--r-- | object.c | 4 | ||||
-rw-r--r-- | test/ruby/test_class.rb | 7 |
2 files changed, 11 insertions, 0 deletions
@@ -2165,6 +2165,10 @@ rb_class_superclass(VALUE klass) if (klass == rb_cBasicObject) return Qnil; rb_raise(rb_eTypeError, "uninitialized class"); } + + if (!RCLASS_SUPERCLASS_DEPTH(klass)) { + return Qnil; + } else { super = RCLASS_SUPERCLASSES(klass)[RCLASS_SUPERCLASS_DEPTH(klass) - 1]; RUBY_ASSERT(RB_TYPE_P(klass, T_CLASS)); diff --git a/test/ruby/test_class.rb b/test/ruby/test_class.rb index 98acbaf67b..a8a019cee2 100644 --- a/test/ruby/test_class.rb +++ b/test/ruby/test_class.rb @@ -96,6 +96,13 @@ class TestClass < Test::Unit::TestCase def test_superclass_of_basicobject assert_equal(nil, BasicObject.superclass) + + assert_separately([], "#{<<~"begin;"}\n#{<<~'end;'}") + begin; + module Mod end + BasicObject.include(Mod) + assert_equal(nil, BasicObject.superclass) + end; end def test_module_function |