GeezerVison is showing github.com — [java] Fix method calls in type resolution by oowekyala · Pull Request #3061 · pmd/pmd
Conversation
oowekyala
commented
Jan 15, 2021
•
edited
Loading
Uh oh!
There was an error while loading. Please reload this page.
Describe the PR
Fix a bug in type resolution, by which expressions like a.m() have type a and not whatever the return type of m is. 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):
+ PrimaryExpression (type = boolean)
+ PrimaryPrefix
+ Name(image = "str.contains", type = boolean)
+ PrimarySuffix
+ Arguments
where nothing hints that the receiver is of type string. Now it's
+ PrimaryExpression (type = boolean)
+ PrimaryPrefix
+ Name(image = "str.contains", type = String) <- this is the receiver type
+ PrimarySuffix (type = boolean)
+ Arguments
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?
- Added unit tests for fixed bug/feature
- Passing all unit tests
- Complete build
./mvnw clean verify passes (checked automatically by travis)
- Added (in-code) documentation (if needed)
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Consider things accessible if we can't resolve this class.
In particular, local variables were inaccessible, which is absurd.
oowekyala
changed the title
[core] Fix method calls in type resolution
[java] Fix method calls in type resolution
Jan 15, 2021
The primary prefix now has the type of the receiver,
when it contains the name of a method call
ghost
commented
Jan 16, 2021
•
edited by ghost
Loading
Uh oh!
There was an error while loading. Please reload this page.
|
1 Message
|
| 📖 |
This changeset changes 16 violations,
introduces 1156 new violations, 0 new errors and 0 new configuration errors,
removes 276 violations, 0 errors and 0 configuration errors.
Full report |
| ✅ |
This changeset changes 0 violations,
introduces 308 new violations, 1 new errors and 0 new configuration errors,
removes 407 violations, 0 errors and 0 configuration errors.
Full report |
| ✅ |
This changeset changes 0 violations,
introduces 308 new violations, 1 new errors and 0 new configuration errors,
removes 407 violations, 0 errors and 0 configuration errors.
Full report |
Generated by 🚫 Danger
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
This was
linked to
issues
Jan 16, 2021
|
Awesome, thanks for working on this! 🚀
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
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.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
|
@uhafner This looks like the result of #2934 (merged for pmd 6.30). I don't think this PR is related
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
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.
|