Commit 567104ce
567104ce028eMerged
Yukihiro "Matz" Matsumoto <[email protected]> · 5 months ago · 3 files · +2 added · ~1 modified
Description
Recognize destructuring targets as ivar assignments
@a, @b = x, y writes its ivars through InstanceVariableTargetNode,
which ivar_written_in? did not recognize (it only matched
InstanceVariableWriteNode and the operator/or/and variants). So
ivar_assigned_in_init_chain? reported the ivars as never assigned,
and widen_uninit_attr_ivars_to_poly widened an attr_reader ivar
initialized solely via destructuring to poly.
For the Comparable <=> pattern that reads @maj <=> other.maj, the
poly ivar made the spaceship mis-dispatch to the user class's own
<=> (the only user-defined spaceship) instead of Integer#<=>, so
a < b came out false and some shapes failed to compile. Adding the
InstanceVariableTargetNode case lets the param types flow into the
ivars exactly as separate @a = x; @b = y assignments already do.
Fixes #1040
Co-Authored-By: Claude Opus 4.8 (1M context) [email protected]
Details
- Commit
- 567104ce028e
- Parent
- cffd0dafed3a
spinel_analyze.rbmodifiedView file
if @nd_type[nid] == "InstanceVariableAndWriteNode" && @nd_name[nid] == iname return 1 end # Destructuring target: `@a, @b = ...` writes @a / @b via # InstanceVariableTargetNode, not InstanceVariableWriteNode. if @nd_type[nid] == "InstanceVariableTargetNode" && @nd_name[nid] == iname return 1 end cs = [] push_child_ids(nid, cs) k = 0test/multi_assign_ivar_type.rbaddedView file
Loading diff…
test/multi_assign_ivar_type.rb.expectedaddedView file
Loading diff…