Commit 120bc157
120bc1576240Merged
Ryan Seys <[email protected]> · 6 months ago · 3 files · +2 added · ~1 modified
Description
fix(codegen): Array#dig single-arg reduces to []
Spinel had no dispatch for Array#dig — the call was warned as
unresolved and lowered to the literal 0. The single-index case
is just arr[idx] (Array#dig recursively walks arr.dig(a, b, c) = arr[a].dig(b, c), but the base step is identical to []).
Adds a single-arg arm to compile_array_method_expr that delegates
to the existing [] handler. Multi-index dig that walks into
nested arrays/hashes isn't covered here yet — falls through to the
unsupported-call warning, same as before.
Test: array_dig.rb covers the single-arg Array#dig case.
Co-Authored-By: Claude Opus 4.7 (1M context) [email protected]
Details
- Commit
- 120bc1576240
- Parent
- 8ff9aa915a30
spinel_codegen.rbmodifiedView file
if is_array_type(recv_type) == 0 return "" end # Array#dig with a single index reduces to []. Multi-arg dig that # walks into nested arrays/hashes isn't supported here yet — fall # through to the unsupported-call warning. if mname == "dig" args_id = @nd_arguments[nid] if args_id >= 0 aargs = get_args(args_id) if aargs.length == 1 return compile_array_method_expr(nid, "[]", rc, recv_type) end end end # arr.slice!(from, n) — returns a fresh array of `n` elements # starting at `from` and removes them from the receiver. Each # array type lowers to its own runtime helper that mutates thetest/array_dig.rbaddedView file
Loading diff…
test/array_dig.rb.expectedaddedView file
Loading diff…