Skip to content

Commit

Permalink
GROOVY-10098
Browse files Browse the repository at this point in the history
  • Loading branch information
eric-milles committed May 20, 2021
1 parent e66f8fb commit d6dfd8b
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2867,4 +2867,27 @@ public void testTypeChecked10091() {
"Groovy:[Static type checking] - Incompatible generic argument types. Cannot assign groovy.lang.Closure<X> to: groovy.lang.Closure<A<java.lang.Number>>\n" +
"----------\n");
}

@Test
public void testTypeChecked10098() {
//@formatter:off
String[] sources = {
"C.groovy",
"@groovy.transform.TupleConstructor(defaults=false)\n" +
"class C<T extends Number> {\n" +
" T p\n" +
" @groovy.transform.TypeChecked\n" +
" T test() {\n" +
" Closure<T> x = { -> p }\n" +
" x()\n" + // Cannot return value of type Object on method returning type T
" }\n" +
" static main(args) {\n" +
" print new C<>(42).test()\n" +
" }\n" +
"}\n",
};
//@formatter:on

runConformTest(sources, "42");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3964,12 +3964,21 @@ public void visitMethodCallExpression(MethodCallExpression call) {
ClassNode type = getType(((ASTNode) variable));
if (type != null && type.equals(CLOSURE_TYPE)) {
GenericsType[] genericsTypes = type.getGenericsTypes();
/* GRECLIPSE edit -- GROOVY-10098
type = OBJECT_TYPE;
if (genericsTypes != null) {
if (!genericsTypes[0].isPlaceholder()) {
type = genericsTypes[0].getType();
}
}
*/
if (genericsTypes != null && genericsTypes.length == 1
&& genericsTypes[0].getLowerBound() == null) {
type = getCombinedBoundType(genericsTypes[0]);
} else {
type = OBJECT_TYPE;
}
// GRECLIPSE end
}
if (type != null) {
storeType(call, type);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3674,12 +3674,21 @@ public void visitMethodCallExpression(final MethodCallExpression call) {
ClassNode type = getType(((ASTNode) variable));
if (type != null && type.equals(CLOSURE_TYPE)) {
GenericsType[] genericsTypes = type.getGenericsTypes();
/* GRECLIPSE edit -- GROOVY-10098
type = OBJECT_TYPE;
if (genericsTypes != null) {
if (!genericsTypes[0].isPlaceholder()) {
type = genericsTypes[0].getType();
}
}
*/
if (genericsTypes != null && genericsTypes.length == 1
&& genericsTypes[0].getLowerBound() == null) {
type = getCombinedBoundType(genericsTypes[0]);
} else {
type = OBJECT_TYPE;
}
// GRECLIPSE end
}
if (type != null) {
storeType(call, type);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3587,10 +3587,19 @@ public void visitMethodCallExpression(final MethodCallExpression call) {
ClassNode type = getType(((ASTNode) variable));
if (CLOSURE_TYPE.equals(type)) {
GenericsType[] genericsTypes = type.getGenericsTypes();
/* GRECLIPSE edit -- GROOVY-10098
type = OBJECT_TYPE;
if (genericsTypes != null && !genericsTypes[0].isPlaceholder()) {
type = genericsTypes[0].getType();
}
*/
if (genericsTypes != null && genericsTypes.length == 1
&& genericsTypes[0].getLowerBound() == null) {
type = getCombinedBoundType(genericsTypes[0]);
} else {
type = OBJECT_TYPE;
}
// GRECLIPSE end
}
if (type != null) {
storeType(call, type);
Expand Down

0 comments on commit d6dfd8b

Please sign in to comment.