Commit 88018fc5

88018fc528c4Merged

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

Description

Coerce poly RHS into a string local on assignment

emit_assign coerced a poly RHS into int/bool/float locals but not string locals, so s = <poly> (where the poly holds a string at runtime) produced an incompatible const char * = sp_RbVal in the generated C. Add the TY_STRING case (sp_poly_to_s), matching the existing scalar coercions.

Emitted-C type errors on the generated legacy compiler: 7 -> 2.

Gates: 845 test, 57 bench, optcarrot checksum 59662 -- all green.

Co-Authored-By: Claude Opus 4.8 (1M context) [email protected]

Details

Commit
88018fc528c4
Parent
0ac0e8657b40

src/codegen_stmt.cmodifiedView file

@@ -493,6 +493,10 @@
493493 else if (lv && lv->type == TY_FLOAT && comp_ntype(c, v) == TY_POLY) {
494494 buf_puts(b, "sp_poly_to_f("); emit_expr(c, v, b); buf_puts(b, ")");
495495 }
496+ else if (lv && lv->type == TY_STRING && comp_ntype(c, v) == TY_POLY) {
497+ /* string slot, poly RHS (holds a string at runtime): coerce */
498+ buf_puts(b, "sp_poly_to_s("); emit_expr(c, v, b); buf_puts(b, ")");
499+ }
496500 else {
497501 emit_expr(c, v, b);
498502 }