Skip to content

Commit

Permalink
GROOVY-9970
Browse files Browse the repository at this point in the history
  • Loading branch information
eric-milles committed Mar 8, 2021
1 parent a7a9911 commit 06f7e59
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1115,4 +1115,32 @@ public void testTypeChecked9968() {

runConformTest(sources, "[x, y, z][x, y, z]");
}

@Test
public void testTypeChecked9970() {
//@formatter:off
String[] sources = {
"Main.groovy",
"@groovy.transform.TupleConstructor\n" +
"class A<T extends B> {\n" +
" T p\n" +
"}\n" +
"class B {\n" +
"}\n" +
"@groovy.transform.TypeChecked\n" +
"class C<T extends Number> {\n" +
" void test(T n) {\n" +
" A<B> x = new A<>(new B())\n" +
" def closure = { ->\n" +
" A<B> y = new A<>(new B())\n" +
" }\n" +
" closure.call()\n" +
" }\n" +
"}\n" +
"new C<Long>().test(42L)\n",
};
//@formatter:on

runConformTest(sources, "");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5518,13 +5518,10 @@ protected ClassNode inferReturnTypeGenerics(
if (resolvedPlaceholders.isEmpty()) {
return boundUnboundedWildcards(returnType);
}
/* GRECLIPSE edit -- GROOVY-9570
/* GRECLIPSE edit -- GROOVY-9570, GROOVY-9735, GROOVY-9970
Map<GenericsTypeName, GenericsType> placeholdersFromContext = extractGenericsParameterMapOfThis(typeCheckingContext.getEnclosingMethod());
*/
Map<GenericsTypeName, GenericsType> placeholdersFromContext = extractGenericsParameterMapOfThis(typeCheckingContext);
// GRECLIPSE end
applyGenericsConnections(placeholdersFromContext, resolvedPlaceholders);

*/
// then resolve receivers from method arguments
Parameter[] parameters = method.getParameters();
boolean isVargs = isVargs(parameters);
Expand Down Expand Up @@ -5570,13 +5567,12 @@ protected ClassNode inferReturnTypeGenerics(
extractGenericsConnections(connections, actualType, type);
extractGenericsConnectionsForSuperClassAndInterfaces(resolvedPlaceholders, connections);
applyGenericsConnections(connections, resolvedPlaceholders);
// GRECLIPSE add -- GROOVY-9735
applyGenericsConnections(placeholdersFromContext, resolvedPlaceholders);
// GRECLIPSE end
}
}
}

// GRECLIPSE add -- GROOVY-9570, GROOVY-9735, GROOVY-9970
applyGenericsConnections(extractGenericsParameterMapOfThis(typeCheckingContext), resolvedPlaceholders);
// GRECLIPSE end
return applyGenericsContext(resolvedPlaceholders, returnType);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5298,8 +5298,9 @@ protected ClassNode inferReturnTypeGenerics(final ClassNode receiver, final Meth
return boundUnboundedWildcards(returnType);
}
Map<GenericsTypeName, GenericsType> placeholdersFromContext = extractGenericsParameterMapOfThis(typeCheckingContext);
/* GRECLIPSE edit -- GROOVY-9970
applyGenericsConnections(placeholdersFromContext, resolvedPlaceholders);

*/
// then resolve receivers from method arguments
List<Expression> expressions = InvocationWriter.makeArgumentList(arguments).getExpressions();
Parameter[] parameters = method.getParameters();
Expand Down Expand Up @@ -5344,11 +5345,15 @@ protected ClassNode inferReturnTypeGenerics(final ClassNode receiver, final Meth
extractGenericsConnectionsForSuperClassAndInterfaces(resolvedPlaceholders, connections);

applyGenericsConnections(connections, resolvedPlaceholders);
/* GRECLIPSE edit -- GROOVY-9970
applyGenericsConnections(placeholdersFromContext, resolvedPlaceholders);
*/
}
}
}

// GRECLIPSE add -- GROOVY-9970
applyGenericsConnections(placeholdersFromContext, resolvedPlaceholders);
// GRECLIPSE end
return applyGenericsContext(resolvedPlaceholders, returnType);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5264,8 +5264,9 @@ protected ClassNode inferReturnTypeGenerics(final ClassNode receiver, final Meth
return boundUnboundedWildcards(returnType);
}
Map<GenericsTypeName, GenericsType> placeholdersFromContext = extractGenericsParameterMapOfThis(typeCheckingContext);
/* GRECLIPSE edit -- GROOVY-9970
applyGenericsConnections(placeholdersFromContext, resolvedPlaceholders);

*/
// then resolve receivers from method arguments
List<Expression> expressions = InvocationWriter.makeArgumentList(arguments).getExpressions();
Parameter[] parameters = method.getParameters();
Expand Down Expand Up @@ -5302,11 +5303,15 @@ protected ClassNode inferReturnTypeGenerics(final ClassNode receiver, final Meth
extractGenericsConnectionsForSuperClassAndInterfaces(resolvedPlaceholders, connections);

applyGenericsConnections(connections, resolvedPlaceholders);
/* GRECLIPSE edit -- GROOVY-9970
applyGenericsConnections(placeholdersFromContext, resolvedPlaceholders);
*/
}
}
}

// GRECLIPSE add -- GROOVY-9970
applyGenericsConnections(placeholdersFromContext, resolvedPlaceholders);
// GRECLIPSE end
return applyGenericsContext(resolvedPlaceholders, returnType);
}

Expand Down

0 comments on commit 06f7e59

Please sign in to comment.