Conversation
Owner
Author
|
@copilot review |
There was a problem hiding this comment.
Pull Request Overview
This PR adds support for instance variables (ivars) to flow-sensitive typing. Previously, flow-sensitive typing only handled local variables (lvars), which limited type narrowing in conditional expressions. The implementation tracks instance variables similarly to local variables, enabling proper type inference for patterns like !@foo.nil? && @foo.upcase.
Key changes:
- Extended
FlowSensitiveTypingclass to track and process instance variables alongside local variables - Modified node processors to thread an
ivarsarray parameter alongside the existinglocalsparameter - Updated
InstanceVariablechain resolution to usevar_at_locationfor flow-sensitive type selection
Reviewed Changes
Copilot reviewed 30 out of 30 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| lib/solargraph/parser/flow_sensitive_typing.rb | Core logic updated to handle ivars in addition to lvars for type narrowing |
| lib/solargraph/parser/node_processor.rb | Added ivars parameter to process method signature and return type |
| lib/solargraph/parser/node_processor/base.rb | Added ivars reader and updated constructor to accept ivars parameter |
| lib/solargraph/parser/parser_gem/class_methods.rb | Modified map method to handle ivars in return value |
| lib/solargraph/parser/parser_gem/node_processors/*.rb | Updated all node processors to thread ivars parameter through processing |
| lib/solargraph/source/chain/instance_variable.rb | Updated resolve method to use var_at_location for flow-sensitive ivar resolution |
| lib/solargraph/library.rb | Removed obsolete @sg-ignore comments for ivar handling |
| lib/solargraph/pin/*.rb | Removed redundant methods and obsolete flow-sensitive typing comments |
| lib/solargraph/type_checker/rules.rb | Updated todo count for flow-sensitive typing improvements |
| spec/type_checker/levels/strong_spec.rb | Added comprehensive tests for ivar flow-sensitive typing |
| spec/type_checker/levels/alpha_spec.rb | Removed pending tests that are now covered |
| spec/source/chain/instance_variable_spec.rb | Updated tests to include location parameters |
| spec/parser/flow_sensitive_typing_spec.rb | Added test for ivar nil check pattern |
| .rubocop_todo.yml | Updated exclusions to reflect code cleanup |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Co-authored-by: apiology <3681194+apiology@users.noreply.github.com>
Fix typo and add instance variable test coverage for flow sensitive typing
apiology
marked this pull request as ready for review
November 27, 2025 15:26
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
…iology/solargraph into union_type_enforcement_ivars
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.
Adds support for doing flow-sensitive typing in instance variables, not just local variables.
Note: This approach assumes single-threaded use for type-checking purposes - it's possible to be clever and subvert it, but as a way to reduce false positives in nil-checking, it seems very effective.
Builds on: