Skip to content

Prioritize RBS ivar declarations over inferred types on read#422

Merged
mame merged 1 commit intomasterfrom
rbs-ivar-precedence
Apr 7, 2026
Merged

Prioritize RBS ivar declarations over inferred types on read#422
mame merged 1 commit intomasterfrom
rbs-ivar-precedence

Conversation

@mame
Copy link
Copy Markdown
Member

@mame mame commented Apr 7, 2026

When an instance variable has an RBS type declaration, IVarReadBox now returns the declared type instead of the union of all assigned types. This prevents nil pollution from base-class initializations like @x = nil from leaking into subclass reads that have declarations.

To make this work regardless of file load order, IVarReadBox subscribes to every ive it visits via add_depended_value_entity, and ValueEntity re-runs those subscribers from on_decl_changed when a declaration is added or removed by SigInstanceVariableNode. Without this, an RBS file loaded after the corresponding Ruby file would leave stale edges from the inferred path in the type graph.

When an instance variable has an RBS type declaration, IVarReadBox now
returns the declared type instead of the union of all assigned types.
This prevents nil pollution from base-class initializations like
@x = nil from leaking into subclass reads that have declarations.

To make this work regardless of file load order, IVarReadBox subscribes
to every ive it visits via add_depended_value_entity, and ValueEntity
re-runs those subscribers from on_decl_changed when a declaration is
added or removed by SigInstanceVariableNode. Without this, an RBS file
loaded after the corresponding Ruby file would leave stale edges from
the inferred path in the type graph.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@mame mame enabled auto-merge (rebase) April 7, 2026 08:59
@mame mame merged commit 720f290 into master Apr 7, 2026
12 checks passed
@mame mame deleted the rbs-ivar-precedence branch April 7, 2026 09:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant