Skip to content

Commit

Permalink
GROOVY-11364: STC: propagate receiver generics to candidate return types
Browse files Browse the repository at this point in the history
3_0_X backport
  • Loading branch information
eric-milles committed Apr 30, 2024
1 parent 69fca65 commit 0cc58e8
Showing 1 changed file with 14 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2497,13 +2497,20 @@ && getType(nameExpr).equals(STRING_TYPE)) {
}

if (!candidates.isEmpty()) {
Map<GenericsTypeName, GenericsType> gts = GenericsUtils.extractPlaceholders(receiverType);
stubMissingTypeVariables(receiverType.redirect().getGenericsTypes(), gts); // GROOVY-11241
candidates.stream().map(candidate -> applyGenericsContext(gts, candidate.getReturnType()))
.reduce(WideningCategories::lowestUpperBound).ifPresent(returnType -> {
ClassNode closureType = wrapClosureType(returnType);
storeType(expression, closureType);
});
stubMissingTypeVariables(receiverType.redirect().getGenericsTypes(), GenericsUtils.extractPlaceholders(receiverType)); // GROOVY-11241

ClassNode commonReturnType = null;
for (MethodNode candidate : candidates) {
ClassNode returnType = candidate.getReturnType();
if (!candidate.isStatic() && GenericsUtils.hasUnresolvedGenerics(returnType)) {
Map<GenericsTypeName, GenericsType> spec = new HashMap<>(); // GROOVY-11364
extractGenericsConnections(spec, receiverType, candidate.getDeclaringClass());
returnType = applyGenericsContext(spec, returnType);
}
commonReturnType = (commonReturnType == null ? returnType
: lowestUpperBound(commonReturnType, returnType));
}
storeType(expression, wrapClosureType(commonReturnType));
expression.putNodeMetaData(MethodNode.class, candidates);
} else if (!(expression instanceof MethodReferenceExpression)) {
ClassNode type = wrapTypeIfNecessary(getType(expression.getExpression()));
Expand Down

0 comments on commit 0cc58e8

Please sign in to comment.