Skip to content

Commit 08a300c

Browse files
committed
GROOVY-10086
1 parent ee73f40 commit 08a300c

4 files changed

Lines changed: 41 additions & 3 deletions

File tree

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

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2704,6 +2704,36 @@ public void testTypeChecked10082() {
27042704
runConformTest(sources, "truetrue");
27052705
}
27062706

2707+
@Test
2708+
public void testTypeChecked10086() {
2709+
//@formatter:off
2710+
String[] sources = {
2711+
"Main.groovy",
2712+
"def m(C<D> c_of_d) {c_of_d.p}\n" +
2713+
"@groovy.transform.TypeChecked\n" +
2714+
"void test() {\n" +
2715+
" m(new C<>(0))\n" +
2716+
"}\n",
2717+
2718+
"Types.groovy",
2719+
"@groovy.transform.TupleConstructor(defaults=false)\n" +
2720+
"class C<T> {\n" +
2721+
" T p\n" +
2722+
"}\n" +
2723+
"class D {\n" +
2724+
"}\n",
2725+
};
2726+
//@formatter:on
2727+
2728+
runNegativeTest(sources,
2729+
"----------\n" +
2730+
"1. ERROR in Main.groovy (at line 4)\n" +
2731+
"\tm(new C<>(0))\n" +
2732+
"\t^^^^^^^^^^^^^\n" +
2733+
"Groovy:[Static type checking] - Cannot call Main#m(C<D>) with arguments [C<java.lang.Integer>]\n" +
2734+
"----------\n");
2735+
}
2736+
27072737
@Test
27082738
public void testTypeChecked10088() {
27092739
//@formatter:off

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6141,7 +6141,7 @@ private static void resolvePlaceholdersFromExplicitTypeHints(final MethodNode me
61416141
* argument is {@code List<T>} without explicit type arguments. Knowning the
61426142
* method target of "m", {@code T} could be resolved.
61436143
*/
6144-
private static void resolvePlaceholdersFromImplicitTypeHints(final ClassNode[] actuals, final ArgumentListExpression argumentList, final Parameter[] parameterArray) {
6144+
private void resolvePlaceholdersFromImplicitTypeHints(final ClassNode[] actuals, final ArgumentListExpression argumentList, final Parameter[] parameterArray) {
61456145
/* GRECLIPSE edit
61466146
for (int i = 0, n = actuals.length; i < n; i += 1) {
61476147
// check for method call with known target
@@ -6174,6 +6174,8 @@ private static void resolvePlaceholdersFromImplicitTypeHints(final ClassNode[] a
61746174
actuals[i] = getLiteralResultType(pt, at, ArrayList_TYPE);
61756175
} else if (a instanceof MapExpression) {
61766176
actuals[i] = getLiteralResultType(pt, at, LINKEDHASHMAP_CLASSNODE);
6177+
} else if (a instanceof ConstructorCallExpression) {
6178+
inferDiamondType((ConstructorCallExpression) a, pt); // GROOVY-10086
61776179
}
61786180

61796181
// check for method call with known target

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5860,7 +5860,7 @@ private static void resolvePlaceholdersFromExplicitTypeHints(final MethodNode me
58605860
* argument is {@code List<T>} without explicit type arguments. Knowning the
58615861
* method target of "m", {@code T} could be resolved.
58625862
*/
5863-
private static void resolvePlaceholdersFromImplicitTypeHints(final ClassNode[] actuals, final ArgumentListExpression argumentList, final Parameter[] parameterArray) {
5863+
private void resolvePlaceholdersFromImplicitTypeHints(final ClassNode[] actuals, final ArgumentListExpression argumentList, final Parameter[] parameterArray) {
58645864
/* GRECLIPSE edit
58655865
for (int i = 0, n = actuals.length; i < n; i += 1) {
58665866
// check for method call with known target
@@ -5893,6 +5893,8 @@ private static void resolvePlaceholdersFromImplicitTypeHints(final ClassNode[] a
58935893
actuals[i] = getLiteralResultType(pt, at, ArrayList_TYPE);
58945894
} else if (a instanceof MapExpression) {
58955895
actuals[i] = getLiteralResultType(pt, at, LINKEDHASHMAP_CLASSNODE);
5896+
} else if (a instanceof ConstructorCallExpression) {
5897+
inferDiamondType((ConstructorCallExpression) a, pt); // GROOVY-10086
58965898
}
58975899

58985900
// check for method call with known target

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5668,7 +5668,7 @@ private static void resolvePlaceholdersFromExplicitTypeHints(final MethodNode me
56685668
* argument is {@code List<T>} without explicit type arguments. Knowning the
56695669
* method target of "m", {@code T} could be resolved.
56705670
*/
5671-
private static void resolvePlaceholdersFromImplicitTypeHints(final ClassNode[] actuals, final ArgumentListExpression argumentList, final Parameter[] parameterArray) {
5671+
private void resolvePlaceholdersFromImplicitTypeHints(final ClassNode[] actuals, final ArgumentListExpression argumentList, final Parameter[] parameterArray) {
56725672
int np = parameterArray.length;
56735673
for (int i = 0, n = actuals.length; np > 0 && i < n; i += 1) {
56745674
Expression a = argumentList.getExpression(i);
@@ -5682,6 +5682,10 @@ private static void resolvePlaceholdersFromImplicitTypeHints(final ClassNode[] a
56825682
actuals[i] = getLiteralResultType(pt, at, ArrayList_TYPE);
56835683
} else if (a instanceof MapExpression) {
56845684
actuals[i] = getLiteralResultType(pt, at, LinkedHashMap_TYPE);
5685+
// GRECLIPSE add
5686+
} else if (a instanceof ConstructorCallExpression) {
5687+
inferDiamondType((ConstructorCallExpression) a, pt); // GROOVY-10086
5688+
// GRECLIPSE end
56855689
}
56865690

56875691
// check for method call with known target

0 commit comments

Comments
 (0)