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

@@ -22774,6 +22774,18 @@
2277422774 if is_array_type(recv_type) == 0
2277522775 return ""
2277622776 end
22777+ # Array#dig with a single index reduces to []. Multi-arg dig that
22778+ # walks into nested arrays/hashes isn't supported here yet — fall
22779+ # through to the unsupported-call warning.
22780+ if mname == "dig"
22781+ args_id = @nd_arguments[nid]
22782+ if args_id >= 0
22783+ aargs = get_args(args_id)
22784+ if aargs.length == 1
22785+ return compile_array_method_expr(nid, "[]", rc, recv_type)
22786+ end
22787+ end
22788+ end
2277722789 # arr.slice!(from, n) — returns a fresh array of `n` elements
2277822790 # starting at `from` and removes them from the receiver. Each
2277922791 # array type lowers to its own runtime helper that mutates the