Commit 180a1a1d

180a1a1dfeddMerged

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

Description

analyze+codegen: fix hash []= return type and poly-hash return boxing

analyze: hash []= should return the value-slot type of the receiving hash, not raw infer_type of the RHS. Previously h[k] = {} on a StrPolyHash returned TY_UNKNOWN (from the untyped {} literal), causing downstream callers to infer wrong return types for methods ending in such an assignment. Fix: unify the inferred RHS type with ty_hash_val(rt) so that TY_UNKNOWN defers to the slot type (TY_POLY for poly-hashes).

codegen: poly-hash []= expression was returning the raw typed temp (const char * for a string value) but the expression's type is now TY_POLY. Box the return value via emit_boxed_text when is_poly_hash.

Fixes lv_widen_from_callee_arg_slot (627 pass, was 626).

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

Details

Commit
180a1a1dfedd
Parent
be113bd22ea2

src/analyze.cmodifiedView file

@@ -1015,7 +1015,7 @@
10151015 }
10161016 if (recv >= 0 && ty_is_hash(rt)) {
10171017 if (!strcmp(name, "[]")) return ty_hash_val(rt);
1018- if (!strcmp(name, "[]=")) return argc >= 2 ? infer_type(c, argv[1]) : ty_hash_val(rt);
1018+ if (!strcmp(name, "[]=")) return argc >= 2 ? ty_unify(infer_type(c, argv[1]), ty_hash_val(rt)) : ty_hash_val(rt);
10191019 if (!strcmp(name, "fetch")) {
10201020 TyKind vt = ty_hash_val(rt);
10211021 int blk = nt_ref(nt, id, "block");