Mauro Molinari created GROOVY-9518:
--------------------------------------
Summary: Closure argument types not inferred when calling a
constructor
Key: GROOVY-9518
URL: https://issues.apache.org/jira/browse/GROOVY-9518
Project: Groovy
Issue Type: Bug
Components: Static Type Checker
Affects Versions: 2.5.11
Reporter: Mauro Molinari
Consider this Java class:
{code:java}
package test64;
import java.util.List;
import java.util.function.BiConsumer;
public class Test64J<Integer> {
public Test64J(String foo, BiConsumer<String, ? super List<Integer>>
bar) {
}
public void doSomething(String foo, BiConsumer<String, ? super
List<Integer>> bar) {
}
}
{code}
and this Groovy class:
{code:groovy}
package test64
import groovy.transform.CompileStatic
@CompileStatic
class Test64 {
void foobar() {
Test64J j = new Test64J('hello', { foo, bar ->
println(bar.size())
})
j.doSomething('hello') { foo, bar ->
println(bar.size())
}
}
}
{code}
The static type checker fails to infer types for {{foo}} and {{bar}} closure
arguments in the constructor call (hence compilation fails on the first
{{println}} call, because it does not know {{bar}} is a {{List}}), while it
succeeds to do the same thing in the method call.
--
This message was sent by Atlassian Jira
(v8.3.4#803005)