Commit 509895a3
509895a3ab3bMerged
Yukihiro "Matz" Matsumoto <[email protected]> · 5 months ago · 3 files · ~3 modified
Description
codegen,analyze: handle bitwise/shift and ||=/&&= on a poly class variable
For a class variable widened to poly under promote: route a bitwise/shift/mod op-assign (<<= >>= &= |= ^= %=) through unbox-op-rebox (cvar = sp_box_int(sp_poly_to_i(cvar) v)), and guard the truthiness in a ||= / &&= with sp_poly_truthy (a raw sp_RbVal is a struct, not a scalar condition), boxing the assigned value and yielding sp_box_nil() for the false arm. Also infer all four class-variable write nodes (write/op/or/and) as the cvar's slot type so a tail does not box the already-poly result twice. Unblocks bundle_class_05; equals prior behaviour for non-widened (default) cvars.
Co-Authored-By: Claude Opus 4.8 [email protected]
Details
- Commit
- 509895a3ab3b
- Parent
- 61f81b6c1563
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 || nk == NK_ClassVariableWriteNode) { /* `@@x op= v` / `@@x = v` writes the cvar and yields the stored value, which the codegen coerces to the cvar's slot type (poly when widened under promote) -- so the expression's type is the cvar's, not v's. (For a non-widened cvar this equals v's type, so default mode is unchanged.) */ if (nk == NK_ClassVariableOperatorWriteNode || nk == NK_ClassVariableWriteNode || nk == NK_ClassVariableOrWriteNode || nk == NK_ClassVariableAndWriteNode) { /* `@@x op= v` / `@@x = v` / `@@x ||= v` / `@@x &&= v` write the cvar and yield the stored value, which the codegen coerces to the cvar's slot type (poly when widened under promote) -- so the expression's type is the cvar's, not v's. (For a non-widened cvar this equals v's type, so default mode is unchanged.) */ const char *nm = nt_str(nt, id, "name"); Scope *s = comp_scope_of(c, id); int cid = s ? s->class_id : -1; if (idx >= 0) return c->classes[cid].cvar_types[idx]; return infer_type(c, nt_ref(nt, id, "value")); } if (nk == NK_ClassVariableOrWriteNode || nk == NK_ClassVariableAndWriteNode) return infer_type(c, nt_ref(nt, id, "value")); if (nk == NK_IndexOrWriteNode || nk == NK_IndexAndWriteNode) { int recv = nt_ref(nt, id, "receiver"); if (recv < 0) return TY_UNKNOWN;src/codegen_expr.cmodifiedView file
Loading diff…
src/codegen_stmt.cmodifiedView file
Loading diff…