At alpha typechecking level, warn on method calls off of nilable types - #803
At alpha typechecking level, warn on method calls off of nilable types#803apiology wants to merge 215 commits into
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.
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.
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.
This is the real win here - the ability to check for potential nil issues
|
Merged into v0.59 release branch |
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: