Commit 70c17fd9

70c17fd90948Merged

Yusuke Endoh <[email protected]> · 6 months ago · 2 files · +1 added · ~1 modified

Description

fix(codegen): scan multi-write ivar targets for type widening

scan_writer_calls already widened ivar types via a direct InstanceVariableWriteNode match, but had no MultiWriteNode branch. A class whose only ivar writes happened through destructuring — e.g. `@pulse_0, @pulse_1, @triangle, @noise, @dmc = pulse_0, pulse_1, triangle, noise, dmc` in optcarrot's APU::Mixer constructor — left every ivar at its initial "int" guess, and the struct came out with mrb_int fields the constructor then tried to fill with pointer values.

Add a MultiWriteNode branch that walks the targets, picks out the InstanceVariableTargetNodes, asks scan_ivars_multi_target_type for the matching RHS slot, and routes through update_ivar_type the same way the single-write branch does.

Co-Authored-By: Claude Opus 4.7 (1M context) [email protected]

Details

Commit
70c17fd90948
Parent
eaad8a4edb93

spinel_codegen.rbmodifiedView file

@@ -8144,6 +8144,30 @@
81448144 end
81458145 end
81468146 end
8147+ # Multi-write to ivars: `@a, @b = pulse_0, pulse_1`. Mirrors the
8148+ # single-write branch above so each ivar's type is widened from
8149+ # the corresponding RHS slot. Without this the multi-write left
8150+ # the ivars at their initial "int" guess and the struct came out
8151+ # with mrb_int fields that the assigning method then tried to
8152+ # overwrite with pointer values.
8153+ if @nd_type[nid] == "MultiWriteNode"
8154+ if @current_class_idx >= 0
8155+ targets_mw = parse_id_list(@nd_targets[nid])
8156+ val_mw = @nd_expression[nid]
8157+ ti_mw = 0
8158+ while ti_mw < targets_mw.length
8159+ tid_mw = targets_mw[ti_mw]
8160+ if @nd_type[tid_mw] == "InstanceVariableTargetNode"
8161+ iname_mw = @nd_name[tid_mw]
8162+ at_mw = scan_ivars_multi_target_type(val_mw, ti_mw)
8163+ if at_mw != "int" && at_mw != "nil"
8164+ update_ivar_type(@current_class_idx, iname_mw, at_mw)
8165+ end
8166+ end
8167+ ti_mw = ti_mw + 1
8168+ end
8169+ end
8170+ end
81478171 if @nd_type[nid] == "CallNode"
81488172 mname = @nd_name[nid]
81498173 recv = @nd_receiver[nid]