You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@groovy.apache.org by "Paul King (Jira)" <ji...@apache.org> on 2020/05/22 04:03:00 UTC
[jira] [Closed] (GROOVY-9518) Closure argument types not inferred
when calling a constructor
[ https://issues.apache.org/jira/browse/GROOVY-9518?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Paul King closed GROOVY-9518.
-----------------------------
> 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
> Assignee: Eric Milles
> Priority: Major
> Fix For: 4.0.0-alpha-1, 3.0.4, 2.5.12
>
> Time Spent: 0.5h
> Remaining Estimate: 0h
>
> 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)