Commit 4d162a3d

4d162a3df945Merged

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

Description

fix(analyze): skip @multi_const_inits for non-constant top-level multi-write

Top-level y, z = call_returning_pair segfaulted: every MultiWriteNode got pushed into @multi_const_inits regardless of whether any target was a constant, so codegen's pre-body init loop planted a bogus _t = call(lv_a, lv_b); emit before the locals it reads from had been assigned. With both args still NULL the inlined method body deref'd NULL and crashed.

Skip the push when no target is a constant; the real destructure runs later through compile_multi_write and lands the correctly GC-rooted call.

Fixes #630.

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

Details

Commit
4d162a3df945
Parent
d17bf68f7f81

spinel_analyze.rbmodifiedView file

@@ -11011,10 +11011,12 @@
1101111011 def collect_scoped_multi_const(scope_name, nid)
1101211012 targets = parse_id_list(@nd_targets[nid])
1101311013 val_id = @nd_expression[nid]
11014+ has_const_target = 0
1101411015 ti = 0
1101511016 while ti < targets.length
1101611017 tid = targets[ti]
1101711018 if @nd_type[tid] == "ConstantTargetNode"
11019+ has_const_target = 1
1101811020 cname = @nd_name[tid]
1101911021 if scope_name != ""
1102011022 cname = scope_name + "_" + cname
@@ -11047,7 +11049,13 @@
1104711049 end
1104811050 end
1104911051 # Record the multi-write as a single deferred init: the RHS is
11050- # evaluated once and each constant takes one element.
11052+ # evaluated once and each constant takes one element. Skip when
11053+ # no target is a constant (top-level `y, z = call_returning_pair`
11054+ # would otherwise plant a bogus pre-body emit that fires before
11055+ # the locals it reads from are assigned, #630).
11056+ if has_const_target == 0
11057+ return
11058+ end
1105111059 if @multi_const_inits == nil
1105211060 @multi_const_inits = "".split(",")
1105311061 end