Commit 5416cf12
5416cf121ecaMerged
Yukihiro "Matz" Matsumoto <[email protected]> · 5 months ago · 1 file · ~1 modified
Description
analyze: nested hash literal as value widens outer hash to poly
When a hash literal has a nested {} (empty hash) as a value, the
outer hash's value type was staying TY_UNKNOWN (from empty-hash
inference) and then unifying with TY_STRING, staying TY_STRING.
This caused {"x" => "v", "nested" => {}} to infer TY_STR_STR_HASH
instead of TY_STR_POLY_HASH, breaking callee-slot back-propagation.
Fix: in the HashNode inference loop, if a value element is a HashNode but typed TY_UNKNOWN (empty literal), treat it as TY_POLY so it widens the outer hash's value slot to a poly variant.
Fixes hash_param_widen_from_callee_slot (628 pass, was 627).
Co-Authored-By: Claude Sonnet 4.6 [email protected]
Details
- Commit
- 5416cf121eca
- Parent
- 180a1a1dfedd
src/analyze.cmodifiedView file
const char *aty = nt_type(nt, els[k]); if (!aty || strcmp(aty, "AssocNode")) return TY_UNKNOWN; kt = ty_unify(kt, infer_type(c, nt_ref(nt, els[k], "key"))); vt = ty_unify(vt, infer_type(c, nt_ref(nt, els[k], "value"))); int vnode = nt_ref(nt, els[k], "value"); TyKind vt_elem = infer_type(c, vnode); /* A nested hash literal (even empty `{}`) is a non-scalar value; treat it as poly so the outer hash promotes to a poly-valued variant. */ if (vt_elem == TY_UNKNOWN) { const char *vnode_ty = nt_type(nt, vnode); if (vnode_ty && (!strcmp(vnode_ty, "HashNode") || !strcmp(vnode_ty, "KeywordHashNode"))) vt_elem = TY_POLY; } vt = ty_unify(vt, vt_elem); } /* symbol keys -> SymPolyHash (boxed values), regardless of value type */ if (kt == TY_SYMBOL) return TY_SYM_POLY_HASH;