Skip to content

Commit

Permalink
GROOVY-10975
Browse files Browse the repository at this point in the history
  • Loading branch information
eric-milles committed Aug 27, 2023
1 parent 7ab6540 commit 045b29e
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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.<String>identity(), List::size)))\n" + (isAtLeastGroovy(50)
? "\t ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" +
"Groovy:[Static type checking] - Cannot call <R,A> java.util.stream.Stream#collect(java.util.stream.Collector<? super java.lang.String, A, R>) with arguments [java.util.stream.Collector<java.util.List, ?, java.util.Map<java.lang.String, java.lang.Integer>>]\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.<String>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");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<Integer> c = [1]\n" +
" Map<Integer,Integer> 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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5412,9 +5412,10 @@ private Map<GenericsTypeName, GenericsType> extractGenericsConnectionsFromArgume
} else { // argument instanceof MethodPointerExpression
List<MethodNode> 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]);
Expand Down

0 comments on commit 045b29e

Please sign in to comment.