[java] Fix method calls in type resolution#3061
Merged
Merged
Conversation
The primary prefix now has the type of the receiver, when it contains the name of a method call
This made tests fail
Generated by 🚫 Danger |
This was
linked to
issues
Jan 16, 2021
Member
|
Awesome, thanks for working on this! 🚀 |
Also add correct imports for GuardLogStatement tests
The test classes have not been compiled, that's why the typeres can't always resolve the classes.
adangel
added a commit
that referenced
this pull request
Jan 21, 2021
[java] Fix method calls in type resolution #3061
|
Does this fix also help for false negatives when comparing enumeration values? I still get warnings with 6.31.0 (see https://github.com/jenkinsci/warnings-ng-plugin/pull/774/checks?check_run_id=1804343680). |
Member
Author
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.
Describe the PR
Fix a bug in type resolution, by which expressions like
a.m()have typeaand not whatever the return type ofmis. The fixed issues are instances of this same problem. It was not introduced in type resolution by 6.30.0, only made discoverable because UseEqualsToCompareStrings was updated to use type resolution in #2934.This could be caused by unresolved local variables, though given how rotten the typeres code is I'm not sure. Other tests are failing now...
update
With these changes, in a call chain, the return type of method calls is now set on the PrimarySuffix that corresponds to the arguments. Previously, it was the PrimarySuffix for the method name, or the PrimaryPrefix, if the receiver is an ambiguous name (ASTName). This was inconsistent and hid the type of the receiver in that case.
Eg
str.contains("")had the following type info (in the best case, whereas with the bug of #2976 the PrimaryExpression has the incorrect type string):where nothing hints that the receiver is of type string. Now it's
I think this is the best we can do on master. I don't want to add tests that will be thrown away when merging 7.0.x, I spent already too much time on this, so this only adds tests to the rules, not the typeres code.
Related issues
Ready?
./mvnw clean verifypasses (checked automatically by travis)