Skip to content

Commit

Permalink
GROOVY-10086
Browse files Browse the repository at this point in the history
  • Loading branch information
eric-milles committed May 16, 2021
1 parent ee73f40 commit 08a300c
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2704,6 +2704,36 @@ public void testTypeChecked10082() {
runConformTest(sources, "truetrue");
}

@Test
public void testTypeChecked10086() {
//@formatter:off
String[] sources = {
"Main.groovy",
"def m(C<D> c_of_d) {c_of_d.p}\n" +
"@groovy.transform.TypeChecked\n" +
"void test() {\n" +
" m(new C<>(0))\n" +
"}\n",

"Types.groovy",
"@groovy.transform.TupleConstructor(defaults=false)\n" +
"class C<T> {\n" +
" T p\n" +
"}\n" +
"class D {\n" +
"}\n",
};
//@formatter:on

runNegativeTest(sources,
"----------\n" +
"1. ERROR in Main.groovy (at line 4)\n" +
"\tm(new C<>(0))\n" +
"\t^^^^^^^^^^^^^\n" +
"Groovy:[Static type checking] - Cannot call Main#m(C<D>) with arguments [C<java.lang.Integer>]\n" +
"----------\n");
}

@Test
public void testTypeChecked10088() {
//@formatter:off
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6141,7 +6141,7 @@ private static void resolvePlaceholdersFromExplicitTypeHints(final MethodNode me
* argument is {@code List<T>} without explicit type arguments. Knowning the
* method target of "m", {@code T} could be resolved.
*/
private static void resolvePlaceholdersFromImplicitTypeHints(final ClassNode[] actuals, final ArgumentListExpression argumentList, final Parameter[] parameterArray) {
private void resolvePlaceholdersFromImplicitTypeHints(final ClassNode[] actuals, final ArgumentListExpression argumentList, final Parameter[] parameterArray) {
/* GRECLIPSE edit
for (int i = 0, n = actuals.length; i < n; i += 1) {
// check for method call with known target
Expand Down Expand Up @@ -6174,6 +6174,8 @@ private static void resolvePlaceholdersFromImplicitTypeHints(final ClassNode[] a
actuals[i] = getLiteralResultType(pt, at, ArrayList_TYPE);
} else if (a instanceof MapExpression) {
actuals[i] = getLiteralResultType(pt, at, LINKEDHASHMAP_CLASSNODE);
} else if (a instanceof ConstructorCallExpression) {
inferDiamondType((ConstructorCallExpression) a, pt); // GROOVY-10086
}

// check for method call with known target
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5860,7 +5860,7 @@ private static void resolvePlaceholdersFromExplicitTypeHints(final MethodNode me
* argument is {@code List<T>} without explicit type arguments. Knowning the
* method target of "m", {@code T} could be resolved.
*/
private static void resolvePlaceholdersFromImplicitTypeHints(final ClassNode[] actuals, final ArgumentListExpression argumentList, final Parameter[] parameterArray) {
private void resolvePlaceholdersFromImplicitTypeHints(final ClassNode[] actuals, final ArgumentListExpression argumentList, final Parameter[] parameterArray) {
/* GRECLIPSE edit
for (int i = 0, n = actuals.length; i < n; i += 1) {
// check for method call with known target
Expand Down Expand Up @@ -5893,6 +5893,8 @@ private static void resolvePlaceholdersFromImplicitTypeHints(final ClassNode[] a
actuals[i] = getLiteralResultType(pt, at, ArrayList_TYPE);
} else if (a instanceof MapExpression) {
actuals[i] = getLiteralResultType(pt, at, LINKEDHASHMAP_CLASSNODE);
} else if (a instanceof ConstructorCallExpression) {
inferDiamondType((ConstructorCallExpression) a, pt); // GROOVY-10086
}

// check for method call with known target
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5668,7 +5668,7 @@ private static void resolvePlaceholdersFromExplicitTypeHints(final MethodNode me
* argument is {@code List<T>} without explicit type arguments. Knowning the
* method target of "m", {@code T} could be resolved.
*/
private static void resolvePlaceholdersFromImplicitTypeHints(final ClassNode[] actuals, final ArgumentListExpression argumentList, final Parameter[] parameterArray) {
private void resolvePlaceholdersFromImplicitTypeHints(final ClassNode[] actuals, final ArgumentListExpression argumentList, final Parameter[] parameterArray) {
int np = parameterArray.length;
for (int i = 0, n = actuals.length; np > 0 && i < n; i += 1) {
Expression a = argumentList.getExpression(i);
Expand All @@ -5682,6 +5682,10 @@ private static void resolvePlaceholdersFromImplicitTypeHints(final ClassNode[] a
actuals[i] = getLiteralResultType(pt, at, ArrayList_TYPE);
} else if (a instanceof MapExpression) {
actuals[i] = getLiteralResultType(pt, at, LinkedHashMap_TYPE);
// GRECLIPSE add
} else if (a instanceof ConstructorCallExpression) {
inferDiamondType((ConstructorCallExpression) a, pt); // GROOVY-10086
// GRECLIPSE end
}

// check for method call with known target
Expand Down

0 comments on commit 08a300c

Please sign in to comment.