Skip to content

Use receiver type for unbound instance method reference in ReplaceLambdaWithMethodReference#909

Merged
timtebeek merged 1 commit into
mainfrom
tim/issue-906
May 28, 2026
Merged

Use receiver type for unbound instance method reference in ReplaceLambdaWithMethodReference#909
timtebeek merged 1 commit into
mainfrom
tim/issue-906

Conversation

@timtebeek
Copy link
Copy Markdown
Member

@timtebeek timtebeek commented May 28, 2026

When ReplaceLambdaWithMethodReference converted an unbound instance reference like s -> 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.

…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.
@github-project-automation github-project-automation Bot moved this to In Progress in OpenRewrite May 28, 2026
@timtebeek timtebeek merged commit 829a5a5 into main May 28, 2026
1 check passed
@timtebeek timtebeek deleted the tim/issue-906 branch May 28, 2026 10:28
@github-project-automation github-project-automation Bot moved this from In Progress to Done in OpenRewrite May 28, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

ReplaceLambdaWithMethodReference resolves to package-private declaring class

1 participant