Skip to content

Commit

Permalink
GROOVY-7789
Browse files Browse the repository at this point in the history
  • Loading branch information
eric-milles committed Nov 5, 2022
1 parent 3c720d9 commit 878d269
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1578,6 +1578,39 @@ public void testTypeChecked7753() {
runConformTest(sources, "[X]");
}

@Test
public void testTypeChecked7789() {
//@formatter:off
String[] sources = {
"Main.groovy",
"import groovy.transform.stc.*\n" +
"@groovy.transform.TypeChecked\n" +
"void test() {\n" +
" def list_size = this.<List>wrap({ list -> list.size() })\n" +
" print list_size([])\n" +
"}\n" +
"def <U> Monad<U> wrap(@ClosureParams(value=FromString, options='U') Closure c) {\n" +
" new Monad<>(c)\n" +
"}\n" +
"test()\n",

"Monad.groovy",
"import groovy.transform.stc.*\n" +
"class Monad<T> {\n" +
" private final Closure c\n" +
" Monad(@ClosureParams(value=FromString, options='T') Closure c) {\n" +
" this.c = c\n" +
" }\n" +
" def call(T t) {\n" +
" c.call(t)\n" +
" }\n" +
"}\n",
};
//@formatter:on

runConformTest(sources, "0");
}

@Test
public void testTypeChecked7804() {
//@formatter:off
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3702,7 +3702,13 @@ private ClassNode[] resolveGenericsFromTypeHint(final ClassNode receiver, final
dummyMN.setDeclaringClass(orig.getDeclaringClass());
dummyMN.setGenericsTypes(orig.getGenericsTypes());
}
ClassNode returnType = inferReturnTypeGenerics(receiver, dummyMN, arguments);
GenericsType[] typeArguments = null; // GROOVY-7789
Expression emc = typeCheckingContext.getEnclosingMethodCall();
if (emc instanceof MethodCallExpression) {
MethodCallExpression call = (MethodCallExpression) emc;
if (arguments == call.getArguments()) typeArguments = call.getGenericsTypes();
}
ClassNode returnType = inferReturnTypeGenerics(receiver, dummyMN, arguments, typeArguments);
GenericsType[] returnTypeGenerics = returnType.getGenericsTypes();
ClassNode[] inferred = new ClassNode[returnTypeGenerics.length];
for (int i = 0, n = returnTypeGenerics.length; i < n; i += 1) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3459,7 +3459,13 @@ private ClassNode[] resolveGenericsFromTypeHint(final ClassNode receiver, final
dummyMN.setDeclaringClass(orig.getDeclaringClass());
dummyMN.setGenericsTypes(orig.getGenericsTypes());
}
ClassNode returnType = inferReturnTypeGenerics(receiver, dummyMN, arguments);
GenericsType[] typeArguments = null; // GROOVY-7789
Expression emc = typeCheckingContext.getEnclosingMethodCall();
if (emc instanceof MethodCallExpression) {
MethodCallExpression call = (MethodCallExpression) emc;
if (arguments == call.getArguments()) typeArguments = call.getGenericsTypes();
}
ClassNode returnType = inferReturnTypeGenerics(receiver, dummyMN, arguments, typeArguments);
GenericsType[] returnTypeGenerics = returnType.getGenericsTypes();
ClassNode[] inferred = new ClassNode[returnTypeGenerics.length];
for (int i = 0, n = returnTypeGenerics.length; i < n; i += 1) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3194,7 +3194,14 @@ private void resolveGenericsFromTypeHint(final ClassNode receiver, final Express
methodNode.setGenericsTypes(selectedMethod.getGenericsTypes());
}

returnType = inferReturnTypeGenerics(receiver, methodNode, arguments);
GenericsType[] typeArguments = null; // GROOVY-7789
Expression emc = typeCheckingContext.getEnclosingMethodCall();
if (emc instanceof MethodCallExpression) {
MethodCallExpression call = (MethodCallExpression) emc;
if (arguments == call.getArguments()) typeArguments = call.getGenericsTypes();
}

returnType = inferReturnTypeGenerics(receiver, methodNode, arguments, typeArguments);
GenericsType[] returnTypeGenerics = returnType.getGenericsTypes();
for (int i = 0, n = returnTypeGenerics.length; i < n; i += 1) {
GenericsType gt = returnTypeGenerics[i];
Expand Down

0 comments on commit 878d269

Please sign in to comment.