fix(jdk-codemodel): resolve implicit lambda parameter types#17
Merged
Conversation
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.
LambdaParameter.typewas non-optional, so implicit lambda parameters ((a, b) -> ...) producedUnknownTypeUsageindistinguishable from a failed resolution of an explicitly-annotated type. This PR fixes that and consolidates the type resolution infrastructure.Changes:
LambdaParameter.typeis nowOptional<TypeUsage>.Optional.empty()means "no annotation and inference unavailable";Optional.of(type)means resolved (whether from an explicit annotation or javac's inferred type).Lambdamarshalling updated to usemarshal(null)/Optional.ofNullable(unmarshal(...))to preserve absence across round-trips.JdkExpressionConvertergainsresolveLambdaParameterType(VariableTree): explicit params wrapresolveTypeUsageinOptional.of; implicit params resolve viatrees.getTypeMirror(TreePath.getPath(compilationUnit, p)).A
resolveTypeMirror(Tree) → Optional<TypeMirror>helper centralises the null/error-kindTypeMirrorchecking logic that was previously duplicated acrossresolveTypeUsage,resolveLambdaParameterType, andresolveReceiverType.JdkStatementConverterno longer maintains its own copy ofresolveTypeUsageor thetrees/compilationUnit/typeResolverfields that supported it. All three call sites now delegate toexprConverter.resolveTypeUsage.setTypeContextremoved; the corresponding call inJdkInitializerremoved.New test
shouldResolveImplicitLambdaParameterTypesverifies that(a, b) -> ...params resolve toStringwhen the target type isComparator<String>. Five existing call sites updated to.type().orElseThrow().