Commit 59aed21e
59aed21e61f0Merged
Yukihiro "Matz" Matsumoto <[email protected]> · 5 months ago · 1 file · ~1 modified
Description
Box ternary branches in a poly context
An if/ternary value with mixed-type branches (a poly result) now boxes each concrete-typed branch instead of emitting a raw C conditional with mismatched arms, fixing the pointer/integer conditional error when the result feeds a poly slot.
Co-Authored-By: Claude Opus 4.8 (1M context) [email protected]
Details
- Commit
- 59aed21e61f0
- Parent
- baf0def3c351
src/codegen.cmodifiedView file
@@ -3595,14 +3595,16 @@
35953595
int en = 0;35963596
const int *eb = else_stmts >= 0 ? nt_arr(nt, else_stmts, "body", &en) : NULL;35973597
if (tn == 1 && en == 1) {3598+
TyKind res = comp_ntype(c, id);35983599
buf_puts(b, "(");35993600
if (is_unless) buf_puts(b, "!(");36003601
emit_cond(c, pred, b);36013602
if (is_unless) buf_puts(b, ")");36023603
buf_puts(b, " ? ");3603-
emit_expr(c, tb[0], b);3604+
/* a poly result with concrete-typed branches boxes each branch */3605+
if (res == TY_POLY && comp_ntype(c, tb[0]) != TY_POLY) emit_boxed(c, tb[0], b); else emit_expr(c, tb[0], b);36043606
buf_puts(b, " : ");3605-
emit_expr(c, eb[0], b);3607+
if (res == TY_POLY && comp_ntype(c, eb[0]) != TY_POLY) emit_boxed(c, eb[0], b); else emit_expr(c, eb[0], b);36063608
buf_puts(b, ")");36073609
return;36083610
}