Commit 21088100

210881000a6cMerged

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

Description

analyze: ArrayPattern *rest LV registered in scan_locals

case x in [a, *rest] (and Array(a, *rest) find-pattern) left lv_rest undeclared because scan_locals's ArrayPatternNode arm only walked requireds, not the splat target.

Walk @nd_rest -> SplatNode -> LocalVariableTargetNode and register the LV with the scrutinee's full array type (the slice keeps the variant: int_array stays int_array, etc.).

Refs #844

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

Details

Commit
210881000a6c
Parent
f87de0478ee6

spinel_analyze.rbmodifiedView file

@@ -26288,6 +26288,22 @@
2628826288 end
2628926289 ap_ri = ap_ri + 1
2629026290 end
26291+ # `case x in [a, *rest]` -- the splat target. Type is the
26292+ # source array's full type (slice keeps the variant). Issue #844.
26293+ ap_rest = @nd_rest[nid]
26294+ if ap_rest >= 0 && @nd_type[ap_rest] == "SplatNode"
26295+ ap_rest_exp = @nd_expression[ap_rest]
26296+ if ap_rest_exp >= 0 && @nd_type[ap_rest_exp] == "LocalVariableTargetNode"
26297+ ap_rname = @nd_name[ap_rest_exp]
26298+ if not_in(ap_rname, names) == 1 && not_in(ap_rname, params) == 1
26299+ names.push(ap_rname)
26300+ types.push(@scan_case_match_pred_type != "" ? @scan_case_match_pred_type : "int_array")
26301+ @scan_literal_flags.push("")
26302+ @scan_empty_flags.push("")
26303+ @scan_empty_hash_flags.push("")
26304+ end
26305+ end
26306+ end
2629126307 end
2629226308 # `case x in {a:, b:}` -- HashPatternNode, the named hash keys
2629326309 # bind to LVs whose type is the hash's value type. Issue #805.