Prioritize RBS ivar declarations over inferred types on read#422
Merged
Conversation
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.