Commit 592a33ad

592a33addfcbMerged

Yusuke Endoh <[email protected]> · 6 months ago · 3 files · +2 added · ~1 modified

Description

fix(codegen): gc_scan skips ivars inherited from parent class

emit_class_struct already skips ivars whose name appears in the parent chain — the subclass's struct uses the inherited field typed by the parent. gc_scan was still walking those names under the child's (potentially widened) recorded type, emitting a mark with the wrong type cast (e.g. parent says int_array, child has widened to poly, struct field is sp_RbVal but the emitted mark used a different cast).

Skip ivars whose name is in the parent chain. The parent's own gc_scan walk handles them via the parent's recorded type, which matches the actual struct field.

Details

Commit
592a33addfcb
Parent
60f1b75ea8d0

spinel_codegen.rbmodifiedView file

@@ -13106,7 +13106,23 @@
1310613106 j = 0
1310713107 while j < names.length
1310813108 if j < types.length
13109- if ivar_is_gc_ptr(types[j]) == 1
13109+ # Skip ivars inherited from parent — emit_class_struct
13110+ # also skips them on the child, so the struct field type
13111+ # comes from the parent's recorded type, and re-emitting
13112+ # here under the child's type info can produce a wrong
13113+ # mark (e.g. parent says int_array, child has widened to
13114+ # poly, struct field is sp_RbVal). The parent walk below
13115+ # marks them via the parent's type.
13116+ skip_inherited = 0
13117+ if @cls_parents[i] != ""
13118+ parent_idx = find_class_idx(@cls_parents[i])
13119+ if parent_idx >= 0
13120+ if ivar_in_chain(parent_idx, names[j]) == 1
13121+ skip_inherited = 1
13122+ end
13123+ end
13124+ end
13125+ if skip_inherited == 0 && ivar_is_gc_ptr(types[j]) == 1
1311013126 emit_gc_mark_ivar("self->" + sanitize_ivar(names[j]), types[j])
1311113127 end
1311213128 end