Skip to content

Commit

Permalink
Fix for #1282: infer param type in case of generics placeholder
Browse files Browse the repository at this point in the history
  • Loading branch information
eric-milles committed Jul 20, 2021
1 parent 6fa25e6 commit 5e8afc4
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -1007,6 +1007,24 @@ public void testClosure14() {
assertEquals("java.lang.String", printTypeName(m.getReturnType()));
}

@Test // https://github.com/groovy/groovy-eclipse/issues/1282
public void testClosure15() {
String contents =
"def <T> void test(Iterator<T> it) {\n" +
" it.forEachRemaining{e->}\n" +
"}\n";
assertType(contents, "e", "T");
}

@Test
public void testClosure16() {
String contents =
"void test(List list) {\n" +
" list.stream().map{e->}\n" +
"}\n";
assertType(contents, "e", "java.lang.Object");
}

@Test
public void testArrayDGM() {
String contents =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -968,7 +968,7 @@ public void visitClosureExpression(final ClosureExpression node) {
Parameter[] parameters = node.getParameters();
for (int i = 0, n = parameters.length; i < n; i += 1) {
// only change the type of the parameter if it's not explicitly defined
if (parameters[i].isDynamicTyped() && !VariableScope.OBJECT_CLASS_NODE.equals(inferredParamTypes[i])) {
if (parameters[i].isDynamicTyped() && (inferredParamTypes[i].isGenericsPlaceHolder() || !inferredParamTypes[i].equals(VariableScope.OBJECT_CLASS_NODE))) {
parameters[i].setType(inferredParamTypes[i]);
}
}
Expand Down

0 comments on commit 5e8afc4

Please sign in to comment.