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

@@ -1556,7 +1556,16 @@
15561556 const char *aty = nt_type(nt, els[k]);
15571557 if (!aty || strcmp(aty, "AssocNode")) return TY_UNKNOWN;
15581558 kt = ty_unify(kt, infer_type(c, nt_ref(nt, els[k], "key")));
1559- vt = ty_unify(vt, infer_type(c, nt_ref(nt, els[k], "value")));
1559+ int vnode = nt_ref(nt, els[k], "value");
1560+ TyKind vt_elem = infer_type(c, vnode);
1561+ /* A nested hash literal (even empty `{}`) is a non-scalar value; treat
1562+ it as poly so the outer hash promotes to a poly-valued variant. */
1563+ if (vt_elem == TY_UNKNOWN) {
1564+ const char *vnode_ty = nt_type(nt, vnode);
1565+ if (vnode_ty && (!strcmp(vnode_ty, "HashNode") || !strcmp(vnode_ty, "KeywordHashNode")))
1566+ vt_elem = TY_POLY;
1567+ }
1568+ vt = ty_unify(vt, vt_elem);
15601569 }
15611570 /* symbol keys -> SymPolyHash (boxed values), regardless of value type */
15621571 if (kt == TY_SYMBOL) return TY_SYM_POLY_HASH;