Skip to content

Commit

Permalink
GROOVY-10230, GROOVY-10344
Browse files Browse the repository at this point in the history
  • Loading branch information
eric-milles committed Nov 4, 2021
1 parent f4a0f02 commit a0d1141
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3936,6 +3936,37 @@ public void testTypeChecked10228() {
runConformTest(sources, "works");
}

@Test
public void testTypeChecked10230() {
//@formatter:off
String[] sources = {
"Main.groovy",
"@groovy.transform.TypeChecked\n" +
"class A {\n" +
" def <T extends C<Number,Number>> T m(T t) {\n" +
" return t\n" +
" }\n" +
"}\n" +
"@groovy.transform.TypeChecked\n" +
"class B extends A {\n" +
" @Override\n" +
" def <T extends C<Number,Number>> T m(T t) {\n" +
" T x = null; super.m(true ? t : x)\n" +
" }\n" +
"}\n" +
"class C<X,Y> {\n" +
"}\n" +
"@groovy.transform.TypeChecked\n" +
"void test() {\n" +
" new B().m(new C<>())\n" +
"}\n" +
"test()\n",
};
//@formatter:on

runConformTest(sources);
}

@Test
public void testTypeChecked10234() {
//@formatter:off
Expand Down Expand Up @@ -4607,4 +4638,24 @@ public void testTypeChecked10339() {
"Groovy:[Static type checking] - Cannot assign value of type java.io.Serializable<? extends java.io.Serializable<java.lang.String>> to variable of type java.lang.Integer\n" +
"----------\n");
}

@Test
public void testTypeChecked10344() {
//@formatter:off
String[] sources = {
"Main.groovy",
"class C<X,Y> {\n" +
"}\n" +
"def <T extends C<? extends Number, ? extends Number>> void m(T t1, T t2) {\n" +
"}\n" +
"@groovy.transform.TypeChecked\n" +
"void test() {\n" +
" m(new C<>(), new C<>())\n" +
"}\n" +
"test()\n",
};
//@formatter:on

runConformTest(sources);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -1217,7 +1217,7 @@ protected void inferDiamondType(final ConstructorCallExpression cce, final Class
// check if constructor call expression makes use of the diamond operator
if (cceType.getGenericsTypes() != null && cceType.getGenericsTypes().length == 0) {
ArgumentListExpression argumentListExpression = InvocationWriter.makeArgumentList(cce.getArguments());
/* GRECLIPSE edit -- GROOVY-9948, GROOVY-9983, GROOVY-10291
/* GRECLIPSE edit -- GROOVY-9948, GROOVY-9983, GROOVY-10291, et al.
if (argumentListExpression.getExpressions().isEmpty()) {
adjustGenerics(lType, cceType);
} else {
Expand Down Expand Up @@ -1251,6 +1251,9 @@ protected void inferDiamondType(final ConstructorCallExpression cce, final Class
}
inferredType = type;
}
if (inferredType.isGenericsPlaceHolder()) // GROOVY-10344: "T t = new C<>()"
inferredType = getCombinedBoundType(inferredType.getGenericsTypes()[0]);

adjustGenerics(inferredType, cceType);
storeType(cce, cceType);
// GRECLIPSE end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1114,7 +1114,7 @@ protected void inferDiamondType(final ConstructorCallExpression cce, final Class
ClassNode cceType = cce.getType(), inferredType = lType;
// check if constructor call expression makes use of the diamond operator
if (cceType.getGenericsTypes() != null && cceType.getGenericsTypes().length == 0) {
/* GRECLIPSE edit -- GROOVY-9948, GROOVY-9983, GROOVY-10291
/* GRECLIPSE edit -- GROOVY-9948, GROOVY-9983, GROOVY-10291, et al.
ArgumentListExpression argumentListExpression = InvocationWriter.makeArgumentList(cce.getArguments());
if (argumentListExpression.getExpressions().isEmpty()) {
adjustGenerics(lType, cceType);
Expand Down Expand Up @@ -1150,6 +1150,9 @@ protected void inferDiamondType(final ConstructorCallExpression cce, final Class
}
inferredType = type;
}
if (inferredType.isGenericsPlaceHolder()) // GROOVY-10344: "T t = new C<>()"
inferredType = getCombinedBoundType(inferredType.getGenericsTypes()[0]);

adjustGenerics(inferredType, cceType);
storeType(cce, cceType);
// GRECLIPSE end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1115,6 +1115,9 @@ protected void inferDiamondType(final ConstructorCallExpression cce, final Class
}
inferredType = type;
}
if (inferredType.isGenericsPlaceHolder()) // GROOVY-10344: "T t = new C<>()"
inferredType = getCombinedBoundType(inferredType.getGenericsTypes()[0]);

adjustGenerics(inferredType, cceType);
storeType(cce, cceType);
}
Expand Down

0 comments on commit a0d1141

Please sign in to comment.