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 0
64176417 end
64186418
6419+ def ivar_exists_in_ancestor(ci, iname)
6420+ if @cls_parents[ci] != ""
6421+ pi = find_class_idx(@cls_parents[ci])
6422+ if pi >= 0
6423+ if ivar_exists(pi, iname) == 1
6424+ return 1
6425+ end
6426+ return ivar_exists_in_ancestor(pi, iname)
6427+ end
6428+ end
6429+ 0
6430+ end
6431+
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) == 0
6517+ if ivar_exists(ci, iname) == 0 && ivar_exists_in_ancestor(ci, iname) == 1
6518+ # Slot is on a parent class — route the write through
6519+ # update_ivar_type so the parent's type widens consistently.
6520+ # Without this, the child re-adds the ivar to its own table
6521+ # with the new write's type, while the parent widens to poly
6522+ # via update_ivar_type's recurse, leaving the two tables
6523+ # disagreeing — and downstream cls_ivar_type lookups on the
6524+ # 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+ end
6529+ elsif ivar_exists(ci, iname) == 0
65056530 vtype = infer_ivar_init_type(expr_first)
65066531 add_ivar(ci, iname, vtype, is_definite_ivar_init(expr_first))
65076532 else