fix: filter out methods not invoked from an identifier#595
Merged
Conversation
`UseCollectionInterfaces.visitMethodInvocation()` was crashing trying to update the identifier type of an identifier-less anonymous object method invocations.
Member
|
Thanks @pdelagrave ! I've made a small change to pull forward the |
timtebeek
approved these changes
Jun 17, 2025
Member
timtebeek
left a comment
There was a problem hiding this comment.
Thanks for working through this one! Good to see the issue resolved and a new case covered.
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.
What's changed?
UseCollectionInterfaces.visitMethodInvocation()will now only proceed if the method was invoked on an expression being an identifier. Anonymous objects don't have an identifier so it doesn't make sense to try to migrate their identifier from a concrete class to an interface.What's your motivation?
UseCollectionInterfaces.visitMethodInvocation()was crashing trying to update the identifier type of an identifier-less anonymous object method invocations.Anyone you would like to review specifically?
@JohannisK who worked on adding the override
UseCollectionInterfaces.visitMethodInvocation()2 months ago.Anything in particular you'd like reviewers to focus on?
Yes, see next section
Have you considered any alternatives or workarounds?
The (only) change at line 156 is:
could have been:
The added test case based from the bug report did crash specifically because of the
visitMethodInvocation()was processing the invocation even if it was for an invocation on an anonymous object which didn't make sense in that context. So skipping it by checking if the expression is exactly that could make sense, but that leave a lot of other expression type that could also not make sense in that context.Specifying that we only want to process expressions that are an identifier narrows down possibilities a lot and might avoid other bugs.
But I'd like a 2nd opinion as even if so far it looks OK and all the tests are passing, this might narrow down when
visitMethodInvocation()runs too much?Any additional context
Checklist