diff options
| author | Jean Boussier <jean.boussier@gmail.com> | 2026-04-12 15:13:03 +0200 |
|---|---|---|
| committer | Takashi Kokubun <takashikkbn@gmail.com> | 2026-04-14 10:34:41 -0700 |
| commit | 3dc2012099a100a0732afa836f1e4cd71660defc (patch) | |
| tree | 635c3911c9b8f90fd0a37d79be289f16ee19dd8c | |
| parent | 949bee21ffe0e18d273f06be65bd0209aaf97384 (diff) | |
iseq.c: rb_estimate_iv_count handle no superclass
[Bug #21992]
When redefining `BasicObject#initialize` there's no super class to
access.
| -rw-r--r-- | iseq.c | 4 | ||||
| -rw-r--r-- | test/ruby/test_super.rb | 14 |
2 files changed, 17 insertions, 1 deletions
@@ -2996,7 +2996,9 @@ rb_estimate_iv_count(VALUE klass, const rb_iseq_t * initialize_iseq) attr_index_t count = (attr_index_t)rb_id_table_size(iv_names); VALUE superclass = rb_class_superclass(klass); - count += RCLASS_MAX_IV_COUNT(superclass); + if (!NIL_P(superclass)) { // BasicObject doesn't have a superclass + count += RCLASS_MAX_IV_COUNT(superclass); + } rb_id_table_free(iv_names); diff --git a/test/ruby/test_super.rb b/test/ruby/test_super.rb index 25bad2242a..39594d74be 100644 --- a/test/ruby/test_super.rb +++ b/test/ruby/test_super.rb @@ -760,6 +760,20 @@ class TestSuper < Test::Unit::TestCase assert_equal 2, inherited.test # it may read index=1 while it should be index=2 end + def test_define_initialize_in_basic_object + assert_separately([], "#{<<~"begin;"}\n#{<<~'end;'}") + begin; + class ::BasicObject + alias_method :initialize, :initialize + def initialize + @bug = "[Bug #21992]" + end + end + + assert_not_nil Object.new + end; + end + def test_super_in_basic_object assert_separately([], "#{<<~"begin;"}\n#{<<~'end;'}") begin; |
