[ https://issues.apache.org/jira/browse/GROOVY-9518?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17088430#comment-17088430 ]
Mauro Molinari commented on GROOVY-9518: ---------------------------------------- Please note closure argument types are not inferred even if I try to help the static type checker in this way: {code:groovy} Test64J j = new Test64J('hello', { foo, bar -> println(bar.size()) } as BiConsumer<String, ? super List<Integer>>) {code} In this case, the Groovy Eclipse Plugin (by [~emilles]) infers {{foo}} and {{bar}} types correctly, but then still fails on the {{println}} call probably because the Groovy static type checker fails. > 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 > Priority: Major > > 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)