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) == 141884188
return rt_va41894189
end4190+
# `hash.values_at(...)` collects the looked-up values, with nil for4191+
# missing keys, into a boxed poly_array.4192+
if is_hash_type(rt_va) == 14193+
return "poly_array"4194+
end4195+
end4196+
end4197+
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 >= 04201+
rt_fv = infer_type(recv)4202+
if is_hash_type(rt_fv) == 14203+
return "poly_array"4204+
end41904205
end41914206
end41924207
if mname == "combination" || mname == "permutation" || mname == "repeated_combination"spinel_codegen.rbmodifiedView file
Loading diff…
test/hash_values_at_fetch_values.rbaddedView file
Loading diff…