Skip to content

Commit a0d1141

Browse files
committed
GROOVY-10230, GROOVY-10344
1 parent f4a0f02 commit a0d1141

File tree

4 files changed

+62
-2
lines changed

4 files changed

+62
-2
lines changed

base-test/org.eclipse.jdt.groovy.core.tests.compiler/src/org/eclipse/jdt/groovy/core/tests/xform/TypeCheckedTests.java

+51
Original file line numberDiff line numberDiff line change
@@ -3936,6 +3936,37 @@ public void testTypeChecked10228() {
39363936
runConformTest(sources, "works");
39373937
}
39383938

3939+
@Test
3940+
public void testTypeChecked10230() {
3941+
//@formatter:off
3942+
String[] sources = {
3943+
"Main.groovy",
3944+
"@groovy.transform.TypeChecked\n" +
3945+
"class A {\n" +
3946+
" def <T extends C<Number,Number>> T m(T t) {\n" +
3947+
" return t\n" +
3948+
" }\n" +
3949+
"}\n" +
3950+
"@groovy.transform.TypeChecked\n" +
3951+
"class B extends A {\n" +
3952+
" @Override\n" +
3953+
" def <T extends C<Number,Number>> T m(T t) {\n" +
3954+
" T x = null; super.m(true ? t : x)\n" +
3955+
" }\n" +
3956+
"}\n" +
3957+
"class C<X,Y> {\n" +
3958+
"}\n" +
3959+
"@groovy.transform.TypeChecked\n" +
3960+
"void test() {\n" +
3961+
" new B().m(new C<>())\n" +
3962+
"}\n" +
3963+
"test()\n",
3964+
};
3965+
//@formatter:on
3966+
3967+
runConformTest(sources);
3968+
}
3969+
39393970
@Test
39403971
public void testTypeChecked10234() {
39413972
//@formatter:off
@@ -4607,4 +4638,24 @@ public void testTypeChecked10339() {
46074638
"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" +
46084639
"----------\n");
46094640
}
4641+
4642+
@Test
4643+
public void testTypeChecked10344() {
4644+
//@formatter:off
4645+
String[] sources = {
4646+
"Main.groovy",
4647+
"class C<X,Y> {\n" +
4648+
"}\n" +
4649+
"def <T extends C<? extends Number, ? extends Number>> void m(T t1, T t2) {\n" +
4650+
"}\n" +
4651+
"@groovy.transform.TypeChecked\n" +
4652+
"void test() {\n" +
4653+
" m(new C<>(), new C<>())\n" +
4654+
"}\n" +
4655+
"test()\n",
4656+
};
4657+
//@formatter:on
4658+
4659+
runConformTest(sources);
4660+
}
46104661
}

base/org.codehaus.groovy25/src/org/codehaus/groovy/transform/stc/StaticTypeCheckingVisitor.java

+4-1
Original file line numberDiff line numberDiff line change
@@ -1217,7 +1217,7 @@ protected void inferDiamondType(final ConstructorCallExpression cce, final Class
12171217
// check if constructor call expression makes use of the diamond operator
12181218
if (cceType.getGenericsTypes() != null && cceType.getGenericsTypes().length == 0) {
12191219
ArgumentListExpression argumentListExpression = InvocationWriter.makeArgumentList(cce.getArguments());
1220-
/* GRECLIPSE edit -- GROOVY-9948, GROOVY-9983, GROOVY-10291
1220+
/* GRECLIPSE edit -- GROOVY-9948, GROOVY-9983, GROOVY-10291, et al.
12211221
if (argumentListExpression.getExpressions().isEmpty()) {
12221222
adjustGenerics(lType, cceType);
12231223
} else {
@@ -1251,6 +1251,9 @@ protected void inferDiamondType(final ConstructorCallExpression cce, final Class
12511251
}
12521252
inferredType = type;
12531253
}
1254+
if (inferredType.isGenericsPlaceHolder()) // GROOVY-10344: "T t = new C<>()"
1255+
inferredType = getCombinedBoundType(inferredType.getGenericsTypes()[0]);
1256+
12541257
adjustGenerics(inferredType, cceType);
12551258
storeType(cce, cceType);
12561259
// GRECLIPSE end

base/org.codehaus.groovy30/src/org/codehaus/groovy/transform/stc/StaticTypeCheckingVisitor.java

+4-1
Original file line numberDiff line numberDiff line change
@@ -1114,7 +1114,7 @@ protected void inferDiamondType(final ConstructorCallExpression cce, final Class
11141114
ClassNode cceType = cce.getType(), inferredType = lType;
11151115
// check if constructor call expression makes use of the diamond operator
11161116
if (cceType.getGenericsTypes() != null && cceType.getGenericsTypes().length == 0) {
1117-
/* GRECLIPSE edit -- GROOVY-9948, GROOVY-9983, GROOVY-10291
1117+
/* GRECLIPSE edit -- GROOVY-9948, GROOVY-9983, GROOVY-10291, et al.
11181118
ArgumentListExpression argumentListExpression = InvocationWriter.makeArgumentList(cce.getArguments());
11191119
if (argumentListExpression.getExpressions().isEmpty()) {
11201120
adjustGenerics(lType, cceType);
@@ -1150,6 +1150,9 @@ protected void inferDiamondType(final ConstructorCallExpression cce, final Class
11501150
}
11511151
inferredType = type;
11521152
}
1153+
if (inferredType.isGenericsPlaceHolder()) // GROOVY-10344: "T t = new C<>()"
1154+
inferredType = getCombinedBoundType(inferredType.getGenericsTypes()[0]);
1155+
11531156
adjustGenerics(inferredType, cceType);
11541157
storeType(cce, cceType);
11551158
// GRECLIPSE end

base/org.codehaus.groovy40/src/org/codehaus/groovy/transform/stc/StaticTypeCheckingVisitor.java

+3
Original file line numberDiff line numberDiff line change
@@ -1115,6 +1115,9 @@ protected void inferDiamondType(final ConstructorCallExpression cce, final Class
11151115
}
11161116
inferredType = type;
11171117
}
1118+
if (inferredType.isGenericsPlaceHolder()) // GROOVY-10344: "T t = new C<>()"
1119+
inferredType = getCombinedBoundType(inferredType.getGenericsTypes()[0]);
1120+
11181121
adjustGenerics(inferredType, cceType);
11191122
storeType(cce, cceType);
11201123
}

0 commit comments

Comments
 (0)