From 045b29ebcd3bf66e5f805bfef01fa294b826f205 Mon Sep 17 00:00:00 2001 From: Eric Milles Date: Fri, 25 Aug 2023 12:05:36 -0500 Subject: [PATCH] GROOVY-10975 --- .../tests/xform/StaticCompilationTests.java | 9 +++------ .../core/tests/xform/TypeCheckedTests.java | 20 +++++++++++++++++++ .../stc/StaticTypeCheckingVisitor.java | 7 ++++--- 3 files changed, 27 insertions(+), 9 deletions(-) diff --git a/base-test/org.eclipse.jdt.groovy.core.tests.compiler/src/org/eclipse/jdt/groovy/core/tests/xform/StaticCompilationTests.java b/base-test/org.eclipse.jdt.groovy.core.tests.compiler/src/org/eclipse/jdt/groovy/core/tests/xform/StaticCompilationTests.java index 430abddc8b..7966f76db8 100644 --- a/base-test/org.eclipse.jdt.groovy.core.tests.compiler/src/org/eclipse/jdt/groovy/core/tests/xform/StaticCompilationTests.java +++ b/base-test/org.eclipse.jdt.groovy.core.tests.compiler/src/org/eclipse/jdt/groovy/core/tests/xform/StaticCompilationTests.java @@ -7307,12 +7307,9 @@ public void testCompileStatic10047b() { runNegativeTest(sources, "----------\n" + "1. ERROR in Main.groovy (at line 5)\n" + - "\tprint(['a','bc','def'].stream().collect(toMap(Function.identity(), List::size)))\n" + (isAtLeastGroovy(50) - ? "\t ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + - "Groovy:[Static type checking] - Cannot call java.util.stream.Stream#collect(java.util.stream.Collector) with arguments [java.util.stream.Collector>]\n" - : "\t ^^^^^^^^^^\n" + - "Groovy:Failed to find class method 'size(java.lang.String)' or instance method 'size()' for the type: java.util.List\n" - ) + + "\tprint(['a','bc','def'].stream().collect(toMap(Function.identity(), List::size)))\n" + + "\t ^^^^^^^^^^\n" + + "Groovy:Failed to find class method 'size(java.lang.String)' or instance method 'size()' for the type: java.util.List\n" + "----------\n"); } 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 4da58c488d..fb4204bd83 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 @@ -6997,6 +6997,26 @@ public void testTypeChecked10897() { runConformTest(sources, "E then C"); } + @Test + public void testTypeChecked10975() { + assumeTrue(isParrotParser()); + + //@formatter:off + String[] sources = { + "Main.groovy", + "@groovy.transform.TypeChecked\n" + + "void test() {\n" + + " Collection c = [1]\n" + + " Map m = [1:1]\n" + + " new Hashtable(Collections.min(c, m::put))\n" + // Cannot find matching constructor Hashtable(Object) + "}\n" + + "test()\n", + }; + //@formatter:on + + runConformTest(sources); + } + @Test public void testTypeChecked10981() { //@formatter:off diff --git a/base/org.codehaus.groovy50/src/org/codehaus/groovy/transform/stc/StaticTypeCheckingVisitor.java b/base/org.codehaus.groovy50/src/org/codehaus/groovy/transform/stc/StaticTypeCheckingVisitor.java index 0684ba36c0..ed8e885022 100644 --- a/base/org.codehaus.groovy50/src/org/codehaus/groovy/transform/stc/StaticTypeCheckingVisitor.java +++ b/base/org.codehaus.groovy50/src/org/codehaus/groovy/transform/stc/StaticTypeCheckingVisitor.java @@ -5412,9 +5412,10 @@ private Map extractGenericsConnectionsFromArgume } else { // argument instanceof MethodPointerExpression List candidates = argument.getNodeMetaData(MethodNode.class); if (candidates != null && !candidates.isEmpty()) { - MethodPointerExpression methodPointer = (MethodPointerExpression) argument; - p = collateMethodReferenceParameterTypes(methodPointer, candidates.get(0)); - if (p.length > 0) { + var methodPointer = (MethodPointerExpression) argument; + p = methodPointer.getNodeMetaData(CLOSURE_ARGUMENTS); // GROOVY-10975 + if (p == null) p = collateMethodReferenceParameterTypes(methodPointer, candidates.get(0)); + if (p.length > 0 && GenericsUtils.hasUnresolvedGenerics(returnType)) { for (int j = 0; j < q.length; j += 1) { // SAM parameters are like arguments in this case extractGenericsConnections(connections, q[j], p[j]);