Commit a3fd8d86

a3fd8d8664b3Merged

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

Description

Box both key and value for PolyPolyHash literal construction

When a hash literal is inferred as TY_POLY_POLY_HASH, sp_PolyPolyHash_set requires both key and value as sp_RbVal. Previously only sym_poly/str_poly hashes boxed their values; poly_poly hashes were passing bare expressions as keys and values, causing gcc -Werror type mismatches.

Co-Authored-By: Claude Sonnet 4.6 [email protected]

Details

Commit
a3fd8d8664b3
Parent
b7a8f2ae3c80

src/codegen.cmodifiedView file

@@ -8323,12 +8323,14 @@
83238323 emit_indent(g_pre, g_indent);
83248324 buf_printf(g_pre, "SP_GC_ROOT(_t%d);\n", t);
83258325 int sym_poly = (ht == TY_SYM_POLY_HASH || ht == TY_STR_POLY_HASH);
8326+ int poly_poly = (ht == TY_POLY_POLY_HASH);
83268327 for (int j = 0; j < n; j++) {
83278328 int key = nt_ref(nt, els[j], "key");
83288329 int val = nt_ref(nt, els[j], "value");
8329- Buf kb; memset(&kb, 0, sizeof kb); emit_expr(c, key, &kb);
8330+ Buf kb; memset(&kb, 0, sizeof kb);
8331+ if (poly_poly) emit_boxed(c, key, &kb); else emit_expr(c, key, &kb);
83308332 Buf vb; memset(&vb, 0, sizeof vb);
8331- if (sym_poly) emit_boxed(c, val, &vb); else emit_expr(c, val, &vb);
8333+ if (sym_poly || poly_poly) emit_boxed(c, val, &vb); else emit_expr(c, val, &vb);
83328334 emit_indent(g_pre, g_indent);
83338335 buf_printf(g_pre, "sp_%sHash_set(_t%d, ", hn, t);
83348336 buf_puts(g_pre, kb.p ? kb.p : ""); buf_puts(g_pre, ", ");