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

@@ -16642,6 +16642,11 @@
1664216642 if @nd_type[nid] == "InstanceVariableAndWriteNode" && @nd_name[nid] == iname
1664316643 return 1
1664416644 end
16645+ # Destructuring target: `@a, @b = ...` writes @a / @b via
16646+ # InstanceVariableTargetNode, not InstanceVariableWriteNode.
16647+ if @nd_type[nid] == "InstanceVariableTargetNode" && @nd_name[nid] == iname
16648+ return 1
16649+ end
1664516650 cs = []
1664616651 push_child_ids(nid, cs)
1664716652 k = 0