Commit 435ea3b7
435ea3b76984Merged
Yukihiro "Matz" Matsumoto <[email protected]> · 5 months ago · 3 files · ~3 modified
Description
codegen,analyze: route widened class-variable op-assign through sp_poly_
A poly-widened class variable cannot use the C compound assignment cvar op= v
(no operator on sp_RbVal). Emit cvar = sp_poly_<op>(cvar, boxed v) in both the
statement and expression forms (mirrors the local op-assign poly arm). Also fix
the inference: a ClassVariableOperatorWriteNode reads-operates-writes the cvar,
so its result type is the cvar's slot type (poly when widened), not the RHS
value's type -- otherwise the tail-return path boxes the already-poly result a
second time. The cvar type equals the old value type for a non-widened int
cvar, so default mode is unchanged. Unblocks op_assign_tail_return.
Co-Authored-By: Claude Opus 4.8 [email protected]
Details
- Commit
- 435ea3b76984
- Parent
- 519739794707
src/analyze_infer.cmodifiedView file
int idx = nm ? comp_cvar_index(&c->classes[cid], nm) : -1; return idx >= 0 ? c->classes[cid].cvar_types[idx] : TY_UNKNOWN; } if (nk == NK_ClassVariableOperatorWriteNode) { /* `@@x op= v` reads, operates, and writes back the cvar, so it yields the cvar's slot type (which may be widened to poly under promote), not v's. */ const char *nm = nt_str(nt, id, "name"); Scope *s = comp_scope_of(c, id); int cid = s ? s->class_id : -1; if (cid < 0) cid = comp_class_index(c, "Toplevel"); int idx = (cid >= 0 && nm) ? comp_cvar_index(&c->classes[cid], nm) : -1; if (idx >= 0) return c->classes[cid].cvar_types[idx]; return infer_type(c, nt_ref(nt, id, "value")); } if (nk == NK_ClassVariableWriteNode || nk == NK_ClassVariableOperatorWriteNode || nk == NK_ClassVariableOrWriteNode || nk == NK_ClassVariableAndWriteNode) return infer_type(c, nt_ref(nt, id, "value"));src/codegen_expr.cmodifiedView file
Loading diff…
src/codegen_stmt.cmodifiedView file
Loading diff…