diff --git a/object.c b/object.c index 15eeda8689..f5f5759d11 100644 --- a/object.c +++ b/object.c @@ -409,10 +409,12 @@ init_copy(VALUE dest, VALUE obj) RBASIC(dest)->flags &= ~(T_MASK|FL_EXIVAR); // Copies the shape id from obj to dest RBASIC(dest)->flags |= RBASIC(obj)->flags & (T_MASK|FL_EXIVAR); - rb_copy_generic_ivar(dest, obj); if (RB_TYPE_P(obj, T_OBJECT)) { rb_obj_copy_ivar(dest, obj); } + else { + rb_copy_generic_ivar(dest, obj); + } rb_gc_copy_attributes(dest, obj); } diff --git a/variable.c b/variable.c index d7f9579d9c..2f8a606930 100644 --- a/variable.c +++ b/variable.c @@ -2438,6 +2438,9 @@ rb_copy_generic_ivar(VALUE dest, VALUE obj) clear: if (FL_TEST(dest, FL_EXIVAR)) { +#if SHAPE_IN_BASIC_FLAGS + RBASIC_SET_SHAPE_ID(dest, ROOT_SHAPE_ID); +#endif rb_free_generic_ivar(dest); FL_UNSET(dest, FL_EXIVAR); }