Commit bc26201f

bc26201f4e60Merged

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

Description

Merge PR #1521: build Array#to_h pair form from each pair's array kind

[[1, 2], [3, 4]].to_h returned {0 => 0}: the pair-form lowering cast each element to sp_PolyArray* and read it with sp_PolyArray_get, but a like-typed pair is a homogeneous typed array (IntArray/StrArray), so the read hit the wrong layout. Key/value are now extracted with sp_poly_arr_get (boxes an element from any array kind via cls_id) then unboxed to the hash's key/value C types; adds the missing poly-key arm and roots the receiver. A non-literal to_h receiver types as POLY_POLY_HASH so unknown pair types are preserved.

Combined-state gates: test 1007/0/0, bench 57/57, optcarrot checksum 59662.

Closes #1521

Co-authored-by: Ryan Seys [email protected] Co-Authored-By: Claude Opus 4.8 [email protected]

Details

Commit
bc26201f4e60
Parent
ab3631c9b24b
Merge parent
9aa9708afdaf

src/analyze_infer.cmodifiedView file

@@ -1903,7 +1903,10 @@
19031903 }
19041904 }
19051905 }
1906- return TY_SYM_POLY_HASH;
1906+ /* Non-literal receiver: the pair element types are not statically known
1907+ (e.g. `a.to_h` for a method param), so a fully boxed hash preserves
1908+ whatever keys/values the pairs hold instead of mis-typing them. */
1909+ return TY_POLY_POLY_HASH;
19071910 }
19081911 }
19091912