Commit debfb670
debfb670e893Merged
Yukihiro "Matz" Matsumoto <[email protected]> · 6 months ago · 2 files · +1 added · ~1 modified
Description
Merge pull request #255 from mame/pr/scan-ivars-no-double-register
fix(codegen): scan_ivars routes writes to parent's slot when inherited
Details
- Commit
- debfb670e893
- Parent
- 9eb374b60f6b
- Merge parent
- d882e601090e
spinel_codegen.rbmodifiedView file
@@ -6416,6 +6416,19 @@
64166416
064176417
end64186418
6419+
def ivar_exists_in_ancestor(ci, iname)6420+
if @cls_parents[ci] != ""6421+
pi = find_class_idx(@cls_parents[ci])6422+
if pi >= 06423+
if ivar_exists(pi, iname) == 16424+
return 16425+
end6426+
return ivar_exists_in_ancestor(pi, iname)6427+
end6428+
end6429+
06430+
end6431+
64196432
def add_ivar(ci, iname, itype, definite = 0)64206433
if @cls_ivar_names[ci] != ""64216434
@cls_ivar_names[ci] = @cls_ivar_names[ci] + ";" + iname@@ -6501,7 +6514,19 @@
65016514
if @nd_type[nid] == "InstanceVariableWriteNode"65026515
iname = @nd_name[nid]65036516
expr_first = @nd_expression[nid]6504-
if ivar_exists(ci, iname) == 06517+
if ivar_exists(ci, iname) == 0 && ivar_exists_in_ancestor(ci, iname) == 16518+
# Slot is on a parent class — route the write through6519+
# update_ivar_type so the parent's type widens consistently.6520+
# Without this, the child re-adds the ivar to its own table6521+
# with the new write's type, while the parent widens to poly6522+
# via update_ivar_type's recurse, leaving the two tables6523+
# disagreeing — and downstream cls_ivar_type lookups on the6524+
# child see only its (narrower) entry, missing the widening.6525+
vtype = infer_ivar_init_type(expr_first)6526+
if vtype != "int" && vtype != "nil"6527+
update_ivar_type(ci, iname, vtype)6528+
end6529+
elsif ivar_exists(ci, iname) == 065056530
vtype = infer_ivar_init_type(expr_first)65066531
add_ivar(ci, iname, vtype, is_definite_ivar_init(expr_first))65076532
elsetest/scan_ivars_inherited_slot.rbaddedView file
Loading diff…