From 08a300c4717f267c93d92ff776f6a61bc0c42609 Mon Sep 17 00:00:00 2001 From: Eric Milles Date: Sat, 15 May 2021 21:21:55 -0500 Subject: [PATCH] GROOVY-10086 --- .../core/tests/xform/TypeCheckedTests.java | 30 +++++++++++++++++++ .../stc/StaticTypeCheckingVisitor.java | 4 ++- .../stc/StaticTypeCheckingVisitor.java | 4 ++- .../stc/StaticTypeCheckingVisitor.java | 6 +++- 4 files changed, 41 insertions(+), 3 deletions(-) diff --git a/base-test/org.eclipse.jdt.groovy.core.tests.compiler/src/org/eclipse/jdt/groovy/core/tests/xform/TypeCheckedTests.java b/base-test/org.eclipse.jdt.groovy.core.tests.compiler/src/org/eclipse/jdt/groovy/core/tests/xform/TypeCheckedTests.java index 284e2f84b8..d1694bb689 100644 --- a/base-test/org.eclipse.jdt.groovy.core.tests.compiler/src/org/eclipse/jdt/groovy/core/tests/xform/TypeCheckedTests.java +++ b/base-test/org.eclipse.jdt.groovy.core.tests.compiler/src/org/eclipse/jdt/groovy/core/tests/xform/TypeCheckedTests.java @@ -2704,6 +2704,36 @@ public void testTypeChecked10082() { runConformTest(sources, "truetrue"); } + @Test + public void testTypeChecked10086() { + //@formatter:off + String[] sources = { + "Main.groovy", + "def m(C 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 {\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) with arguments [C]\n" + + "----------\n"); + } + @Test public void testTypeChecked10088() { //@formatter:off diff --git a/base/org.codehaus.groovy25/src/org/codehaus/groovy/transform/stc/StaticTypeCheckingVisitor.java b/base/org.codehaus.groovy25/src/org/codehaus/groovy/transform/stc/StaticTypeCheckingVisitor.java index 86959a3baf..6fcac82ac1 100644 --- a/base/org.codehaus.groovy25/src/org/codehaus/groovy/transform/stc/StaticTypeCheckingVisitor.java +++ b/base/org.codehaus.groovy25/src/org/codehaus/groovy/transform/stc/StaticTypeCheckingVisitor.java @@ -6141,7 +6141,7 @@ private static void resolvePlaceholdersFromExplicitTypeHints(final MethodNode me * argument is {@code List} 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 @@ -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 diff --git a/base/org.codehaus.groovy30/src/org/codehaus/groovy/transform/stc/StaticTypeCheckingVisitor.java b/base/org.codehaus.groovy30/src/org/codehaus/groovy/transform/stc/StaticTypeCheckingVisitor.java index 29cb4e350a..84ed1519a9 100644 --- a/base/org.codehaus.groovy30/src/org/codehaus/groovy/transform/stc/StaticTypeCheckingVisitor.java +++ b/base/org.codehaus.groovy30/src/org/codehaus/groovy/transform/stc/StaticTypeCheckingVisitor.java @@ -5860,7 +5860,7 @@ private static void resolvePlaceholdersFromExplicitTypeHints(final MethodNode me * argument is {@code List} 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 @@ -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 diff --git a/base/org.codehaus.groovy40/src/org/codehaus/groovy/transform/stc/StaticTypeCheckingVisitor.java b/base/org.codehaus.groovy40/src/org/codehaus/groovy/transform/stc/StaticTypeCheckingVisitor.java index a39ee87e39..42d6998c18 100644 --- a/base/org.codehaus.groovy40/src/org/codehaus/groovy/transform/stc/StaticTypeCheckingVisitor.java +++ b/base/org.codehaus.groovy40/src/org/codehaus/groovy/transform/stc/StaticTypeCheckingVisitor.java @@ -5668,7 +5668,7 @@ private static void resolvePlaceholdersFromExplicitTypeHints(final MethodNode me * argument is {@code List} 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); @@ -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