fix: resolve constructor references via context rather than constructed type#5030
Merged
Conversation
added 2 commits
May 30, 2026 19:02
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #5030 +/- ##
===============================================
+ Coverage 58.686% 58.692% +0.005%
- Complexity 2595 2599 +4
===============================================
Files 702 702
Lines 40282 40295 +13
Branches 7342 7349 +7
===============================================
+ Hits 23640 23650 +10
Misses 13667 13667
- Partials 2975 2978 +3
Flags with carried forward coverage won't be shown. Click here to find out more.
... and 1 file with indirect coverage changes Continue to review full report in Codecov by Sentry.
🚀 New features to boost your workflow:
|
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.
TypeExtractor previously short-circuited all ::new method references by
returning the constructed type (e.g. String for String::new). Per JLS
§15.13, a constructor reference is a poly expression: its type is the
functional interface it satisfies in context, not the type it constructs.
Remove the early return and let constructor references fall through to the
same parent-context logic used for ordinary method references:
position (solveLambdas=false), or perform full inference via
FunctionalInterfaceLogic (solveLambdas=true). The toMethodUsage()
inference step is skipped for ::new because constructors are not
returned by getAllMethods(); skipping is safe since a constructor always
returns the constructed type, matching the functional interface's return
type exactly, so the inference pair carries no new information.
Combined with the matchTypeParameters wildcard fix, this allows
Collectors.groupingBy(String::new, Collectors.counting()) to resolve
without throwing UnsolvedSymbolException. Full inference of K=String
requires two-phase poly-expression inference (JLS §15.12.2.7) which is
not yet implemented.
Add Javadoc to visit(MethodReferenceExpr) documenting all handled cases.
Add two regression tests covering the MethodCallExpr and VariableDeclarator
contexts.