Commit f4869a2e
f4869a2e1761Merged
Yukihiro "Matz" Matsumoto <[email protected]> · 5 months ago · 1 file · ~1 modified
Description
Fix empty {} hash literal with unknown type in emit_expr and emit_arg_or_default
When a hash literal {} has TY_UNKNOWN type (not yet inferred), emit_expr would hit unsupported(). Two fixes:
-
emit_arg_or_default: when the default or provided argument is an empty {} literal with unknown type, emit the constructor matching the parameter's declared type (mirroring the existing [] array fix).
-
emit_expr: when a HashNode/KeywordHashNode has TY_UNKNOWN and zero elements, fall back to sp_StrPolyHash_new() rather than unsupported().
Fixes bundle_class_11, hash_param_widen_from_callee_slot, ivar_assign_and_expr, and lv_widen_from_callee_arg_slot.
Co-Authored-By: Claude Sonnet 4.6 [email protected]
Details
- Commit
- f4869a2e1761
- Parent
- 87bb556ca4b0
src/codegen.cmodifiedView file
if (pt == TY_POLY_ARRAY) buf_puts(out, "sp_PolyArray_new()"); else { const char *k = array_kind(pt); if (k) buf_printf(out, "sp_%sArray_new()", k); else emit_expr(c, provided, out); } } else emit_expr(c, provided, out); /* empty hash literal `{}` with unknown type: use the parameter's type */ else { int phn = 0; int is_empty_hash = pty_node && (!strcmp(pty_node, "HashNode") || !strcmp(pty_node, "KeywordHashNode")) && (nt_arr(c->nt, provided, "elements", &phn), phn == 0); TyKind at2 = comp_ntype(c, provided); if (is_empty_hash && at2 == TY_UNKNOWN && ty_is_hash(pt)) { const char *hn = ty_hash_cname(pt); if (hn) buf_printf(out, "sp_%sHash_new()", hn); else emit_expr(c, provided, out); } else emit_expr(c, provided, out); } } return; } if (pt == TY_POLY_ARRAY) buf_puts(out, "sp_PolyArray_new()"); else { const char *k = array_kind(pt); if (k) buf_printf(out, "sp_%sArray_new()", k); else emit_expr(c, dv, out); } } else emit_expr(c, dv, out); /* Default empty `{}` literal: emit the correct hash constructor for the parameter type, avoiding the "unsupported hash literal" fallback. */ else { int dhn = 0; int is_empty_hash_dv = dty && (!strcmp(dty, "HashNode") || !strcmp(dty, "KeywordHashNode")) && (nt_arr(c->nt, dv, "elements", &dhn), dhn == 0); if (is_empty_hash_dv && ty_is_hash(pt)) { const char *hn = ty_hash_cname(pt); if (hn) buf_printf(out, "sp_%sHash_new()", hn); else emit_expr(c, dv, out); } else emit_expr(c, dv, out); } }} if (!strcmp(ty, "HashNode") || !strcmp(ty, "KeywordHashNode")) { TyKind ht = comp_ntype(c, id); const char *hn = ty_hash_cname(ht); if (!hn) unsupported(c, id, "hash literal (key/value type)"); if (!hn) { /* Empty `{}` with unknown type: fall back to StrPolyHash */ int ne2 = 0; nt_arr(nt, id, "elements", &ne2); if (ne2 == 0) hn = "StrPoly"; else unsupported(c, id, "hash literal (key/value type)"); } int n = 0; const int *els = nt_arr(nt, id, "elements", &n); int t = ++g_tmp;