Use receiver type for unbound instance method reference in ReplaceLambdaWithMethodReference#909
Merged
Conversation
…mbdaWithMethodReference` Previously the recipe used the method's declaring type to construct the class name, which produced uncompilable references like `Base::getValue` (with an inaccessible import) when the declaring class was package-private and the receiver was a public subclass.
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.
When
ReplaceLambdaWithMethodReferenceconverted an unbound instance reference likes -> s.method(), it built the class name from the method's declaring type. If that type was package-private and the receiver was a public subclass in another package, the result (e.g.Base::getValue) failed to compile because the declaring class could not be imported.This change uses the receiver/select type to construct the class name for unbound instance method references, falling back to the declaring type only when the select type is not a fully-qualified type. Static method references continue to use the declaring type unchanged.
Added a regression test reproducing the three-file scenario from the issue.