Commit b37fff07

b37fff07e5fbMerged

Yukihiro "Matz" Matsumoto <[email protected]> · 5 months ago · 1 file · ~1 modified

Description

codegen: unbox a poly pinned value against a scalar scrutinee in pattern match

A pin pattern (in ^x) with a scalar scrutinee emitted a raw C == against the pinned value; when that value is poly (widened under promote) the sp_RbVal struct cannot be compared to a scalar. Unbox it to the scrutinee type via emit_unbox_text. Poly-gated, so default mode is unchanged. Unblocks pattern_pin.

Co-Authored-By: Claude Opus 4.8 [email protected]

Details

Commit
b37fff07e5fb
Parent
509895a3ab3b

src/codegen_stmt.cmodifiedView file

@@ -983,7 +983,15 @@
983983 buf_printf(b, "sp_str_eq(_t%d, ", t); emit_expr(c, valnode, b); buf_puts(b, ")");
984984 }
985985 else {
986- buf_printf(b, "(_t%d == ", t); emit_expr(c, valnode, b); buf_puts(b, ")");
986+ buf_printf(b, "(_t%d == ", t);
987+ if (comp_ntype(c, valnode) == TY_POLY) {
988+ /* a pinned poly value (e.g. `in ^x` with x widened) against a scalar
989+ scrutinee: unbox it to the scrutinee's type so the C `==` typechecks. */
990+ Buf vb; memset(&vb, 0, sizeof vb); emit_expr(c, valnode, &vb);
991+ emit_unbox_text(c, pt, vb.p ? vb.p : "", b); free(vb.p);
992+ }
993+ else emit_expr(c, valnode, b);
994+ buf_puts(b, ")");
987995 }
988996 }
989997