Skip to content

Commit

Permalink
GROOVY-11168: STC: @DelegatesTo(type= type parameter resolution
Browse files Browse the repository at this point in the history
  • Loading branch information
eric-milles committed Sep 20, 2023
1 parent 4b14f7d commit 8ad9575
Show file tree
Hide file tree
Showing 2 changed files with 222 additions and 275 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,7 @@ public class StaticTypeCheckingVisitor extends ClassCodeVisitorSupport {
protected static final ClassNode ITERABLE_TYPE = ClassHelper.make(Iterable.class);
private static final ClassNode SET_TYPE = ClassHelper.make(Set.class);

private static List<ClassNode> TUPLE_TYPES = Arrays.stream(ClassHelper.TUPLE_CLASSES).map(ClassHelper::makeWithoutCaching).collect(Collectors.toList());
private static final List<ClassNode> TUPLE_TYPES = Arrays.stream(ClassHelper.TUPLE_CLASSES).map(ClassHelper::makeWithoutCaching).collect(Collectors.toList());

public static final Statement GENERATED_EMPTY_STATEMENT = EmptyStatement.INSTANCE;

Expand Down Expand Up @@ -3248,7 +3248,7 @@ private void processClosureParams(final ClassNode receiver, final Expression arg
* of failure.
*/
private void resolveGenericsFromTypeHint(final ClassNode receiver, final Expression arguments, final MethodNode selectedMethod, final ClassNode[] signature) {
ClassNode returnType = new ClassNode("ClForInference$" + UNIQUE_LONG.incrementAndGet(), 0, OBJECT_TYPE).getPlainNodeReference();
ClassNode returnType = new ClassNode("ClForInference$" + UNIQUE_LONG.incrementAndGet(), 0, null).getPlainNodeReference();
returnType.setGenericsTypes(Arrays.stream(signature).map(ClassNode::asGenericsType).toArray(GenericsType[]::new));

MethodNode methodNode = selectedMethod instanceof ExtensionMethodNode ? ((ExtensionMethodNode) selectedMethod).getExtensionMethodNode() : selectedMethod;
Expand All @@ -3270,11 +3270,12 @@ private void resolveGenericsFromTypeHint(final ClassNode receiver, final Express
methodNode.setGenericsTypes(selectedMethod.getGenericsTypes());
}

GenericsType[] typeArguments = null; // GROOVY-7789
Expression emc = typeCheckingContext.getEnclosingMethodCall();
if (emc instanceof MethodCallExpression) {
MethodCallExpression call = (MethodCallExpression) emc;
if (arguments == call.getArguments()) typeArguments = call.getGenericsTypes();
GenericsType[] typeArguments = null;
Expression emc = typeCheckingContext.getEnclosingMethodCall(); // GROOVY-7789, GROOVY-11168
if (emc instanceof MethodCallExpression) { MethodCallExpression call = (MethodCallExpression) emc;
if (arguments == call.getArguments() || InvocationWriter.makeArgumentList(arguments).getExpressions().stream().anyMatch(arg ->
arg instanceof ClosureExpression && DefaultGroovyMethods.contains(InvocationWriter.makeArgumentList(call.getArguments()), arg)))
typeArguments = call.getGenericsTypes();
}

returnType = inferReturnTypeGenerics(receiver, methodNode, arguments, typeArguments);
Expand Down
Loading

0 comments on commit 8ad9575

Please sign in to comment.