Fix remove_instance_variable for too complex generic ivar

This commit is contained in:
Peter Zhu 2023-10-31 17:04:40 -04:00
parent 60e207b47f
commit c3b7f27561
2 changed files with 12 additions and 1 deletions

View File

@ -287,6 +287,9 @@ class TestShapes < Test::Unit::TestCase
tc = TooComplex.new
tc.instance_variable_set(:@a, 1)
tc.instance_variable_set(:@b, 2)
tc.remove_instance_variable(:@a)
assert_nil(tc.instance_variable_get(:@a))
end;
end

View File

@ -2217,7 +2217,15 @@ rb_obj_remove_instance_variable(VALUE obj, VALUE name)
break;
}
default: {
rb_shape_transition_shape_remove_ivar(obj, id, shape, &val);
if (rb_shape_obj_too_complex(obj)) {
struct gen_ivtbl *ivtbl;
if (rb_gen_ivtbl_get(obj, 0, &ivtbl)) {
st_delete(ivtbl->as.complex.table, (st_data_t *)&id, (st_data_t *)&val);
}
}
else {
rb_shape_transition_shape_remove_ivar(obj, id, shape, &val);
}
break;
}
}