Fix iv_count for too_complex generic ivar

Previously this branch forgot to assign iv_count when used with a
generic ivar which is too_complex, which could result in it incorrectly
returning 0.
This commit is contained in:
John Hawthorn committed 2026-04-26 17:14:39 +09:00
1 parent 97c070c244
commit 96cd1bc765
2 files changed
+29 -1
Notes: git 2026-04-26 08:15:10 +00:00

No files matched your search

+28
View File
@@ -970,6 +970,34 @@ class TestObject < Test::Unit::TestCase
assert_not_include(s, "@password=")
end
def test_inspect_too_complex
kernel_inspect = Kernel.instance_method(:inspect)
klasses = [
Class.new,
Class.new(String),
Class.new(Array),
Class.new(Hash),
Struct.new(:x),
Class.new(Thread::Mutex),
# It's very difficult to get a too_complex T_CLASS, to that isn't tested here
]
klasses.each_with_index do |klass, idx|
8.times do |i|
klass.new.instance_variable_set(:"@sib_#{rand(999999)}", 1)
end
obj = klass.new
obj.instance_variable_set(:@a, 1)
obj.instance_variable_set(:@b, 2)
s = kernel_inspect.bind_call(obj)
assert_include(s, "@a=1")
assert_include(s, "@b=2")
end
end
def test_singleton_methods
assert_equal([], Object.new.singleton_methods)
assert_equal([], Object.new.singleton_methods(false))
+1 -1
View File
@@ -2402,7 +2402,7 @@ rb_ivar_count(VALUE obj)
VALUE fields_obj = rb_obj_fields_no_ractor_check(obj);
if (fields_obj) {
if (rb_shape_obj_too_complex_p(fields_obj)) {
rb_st_table_size(rb_imemo_fields_complex_tbl(fields_obj));
iv_count = rb_st_table_size(rb_imemo_fields_complex_tbl(fields_obj));
}
else {
iv_count = RBASIC_FIELDS_COUNT(obj);