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
end end end # Multi-write to ivars: `@a, @b = pulse_0, pulse_1`. Mirrors the # single-write branch above so each ivar's type is widened from # the corresponding RHS slot. Without this the multi-write left # the ivars at their initial "int" guess and the struct came out # with mrb_int fields that the assigning method then tried to # overwrite with pointer values. if @nd_type[nid] == "MultiWriteNode" if @current_class_idx >= 0 targets_mw = parse_id_list(@nd_targets[nid]) val_mw = @nd_expression[nid] ti_mw = 0 while ti_mw < targets_mw.length tid_mw = targets_mw[ti_mw] if @nd_type[tid_mw] == "InstanceVariableTargetNode" iname_mw = @nd_name[tid_mw] at_mw = scan_ivars_multi_target_type(val_mw, ti_mw) if at_mw != "int" && at_mw != "nil" update_ivar_type(@current_class_idx, iname_mw, at_mw) end end ti_mw = ti_mw + 1 end end end if @nd_type[nid] == "CallNode" mname = @nd_name[nid] recv = @nd_receiver[nid]test/multi_write_ivar_widening.rbaddedView file
Loading diff…