-
-
Notifications
You must be signed in to change notification settings - Fork 165
At alpha typechecking level, warn on method calls off of nilable types #803
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
More specifically, require that all unique types of a complex type offer the same method before it can match.
|
Realistically, there's enough |
```sh
$ SOLARGRAPH_ASSERTS=on bundle exec solargraph method_pin --rbs 'RuboCop::AST::ArrayNode#values'
def values: () -> Array
$ bundle exec solargraph help method_pin
Usage:
solargraph method_pin [PATH]
Options:
[--rbs], [--no-rbs], [--skip-rbs] # Output the pin as RBS
# Default: false
[--typify], [--no-typify], [--skip-typify] # Output the calculated return type of the pin from annotations
# Default: false
[--probe], [--no-probe], [--skip-probe] # Output the calculated return type of the pin from annotations and inference
# Default: false
[--stack], [--no-stack], [--skip-stack] # Show entire stack by including definitions in superclasses
# Default: false
Describe a method pin
$
```
| # ::Array<::Solargraph::ComplexType::UniqueType> does not match | ||
| # inferred type ::Array<::Proc> for Solargraph::ComplexType#map | ||
| def map(&block) | ||
| @items.map(&block) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I suspect we're not understanding the &block construct
| if !api_map.loose_unions && pin_groups.any? { |pins| pins.empty? } | ||
| pin_groups = [] | ||
| end | ||
| pins = pin_groups.flatten.uniq(&:path) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a key bit - sharpening our existing behavior when asked to require all union types to match the behavior.
…raph into stricter_unions
| expect(checker.problems.map(&:message)) | ||
| .to eq(['Wrong argument type for #foo: a expected String, received String, nil']) | ||
| end | ||
| end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is the real win here - the ability to check for potential nil issues
Require that all unique types of a complex type offer the same method before it can match when "loose unions" mode is turned off.
Depends on:
Included to fix build:
Includes for convenience: