Commit cc46c1a4

cc46c1a4533cMerged

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

Description

Implement Hash#values_at / #fetch_values on typed hashes

{a: 1}.values_at(:a, :z) and #fetch_values previously raised "cannot resolve call" on every typed hash variant. Look each key up via the variant's has_key/get pair and collect the values into a boxed poly_array, so mixed value types and the missing-key nil coexist cleanly. values_at yields nil for a missing key; fetch_values raises KeyError. Covers the sym/str/int-keyed int/str/poly-valued variants.

Refs #1227

Co-Authored-By: Claude Opus 4.8 [email protected]

Details

Commit
cc46c1a4533c
Parent
40eca6faf074

spinel_analyze.rbmodifiedView file

@@ -4187,6 +4187,21 @@
41874187 if is_array_type(rt_va) == 1
41884188 return rt_va
41894189 end
4190+ # `hash.values_at(...)` collects the looked-up values, with nil for
4191+ # missing keys, into a boxed poly_array.
4192+ if is_hash_type(rt_va) == 1
4193+ return "poly_array"
4194+ end
4195+ end
4196+ end
4197+ if mname == "fetch_values"
4198+ # `hash.fetch_values(...)` is values_at that raises on a missing key;
4199+ # the present-key values are boxed into a poly_array.
4200+ if recv >= 0
4201+ rt_fv = infer_type(recv)
4202+ if is_hash_type(rt_fv) == 1
4203+ return "poly_array"
4204+ end
41904205 end
41914206 end
41924207 if mname == "combination" || mname == "permutation" || mname == "repeated_combination"