Commit a3bea7cc

a3bea7cc5b1fMerged

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

Description

Coerce a concrete hash argument in str_poly_hash#merge

A str_poly_hash merged with a concrete str_str/str_int hash now coerces the argument to str_poly (sp_StrPolyHash_from_*) before the merge, fixing the incompatible-pointer compile.

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

Details

Commit
a3bea7cc5b1f
Parent
7a8c9770711a

src/codegen.cmodifiedView file

@@ -2174,7 +2174,16 @@
21742174 }
21752175 if (!strcmp(name, "merge") && argc == 1 &&
21762176 (rt == TY_STR_INT_HASH || rt == TY_STR_POLY_HASH || rt == TY_SYM_POLY_HASH)) {
2177- buf_printf(b, "sp_%sHash_merge(", hn); emit_expr(c, recv, b); buf_puts(b, ", "); emit_expr(c, argv[0], b); buf_puts(b, ")");
2177+ buf_printf(b, "sp_%sHash_merge(", hn); emit_expr(c, recv, b); buf_puts(b, ", ");
2178+ /* a str_poly receiver may be merged with a concrete str-keyed hash;
2179+ coerce the argument to the receiver's variant first */
2180+ TyKind at = comp_ntype(c, argv[0]);
2181+ if (rt == TY_STR_POLY_HASH && (at == TY_STR_STR_HASH || at == TY_STR_INT_HASH)) {
2182+ buf_printf(b, "sp_StrPolyHash_from_%s(", at == TY_STR_STR_HASH ? "str_str_hash" : "str_int_hash");
2183+ emit_expr(c, argv[0], b); buf_puts(b, ")");
2184+ }
2185+ else emit_expr(c, argv[0], b);
2186+ buf_puts(b, ")");
21782187 return;
21792188 }
21802189 if (!strcmp(name, "delete") && argc == 1 &&