You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@groovy.apache.org by "Eric Milles (Jira)" <ji...@apache.org> on 2021/06/08 22:17:00 UTC

[jira] [Commented] (GROOVY-5881) Type inference breaks in longer transitive generic structures

    [ https://issues.apache.org/jira/browse/GROOVY-5881?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17359594#comment-17359594 ] 

Eric Milles commented on GROOVY-5881:
-------------------------------------

See also GROOVY-6324

> Type inference breaks in longer transitive generic structures
> -------------------------------------------------------------
>
>                 Key: GROOVY-5881
>                 URL: https://issues.apache.org/jira/browse/GROOVY-5881
>             Project: Groovy
>          Issue Type: Bug
>          Components: Static Type Checker
>    Affects Versions: 2.0.6, 2.3.0, 2.4.0-beta-3
>            Reporter: Dimitar Dimitrov
>            Priority: Major
>
> {code}
> class Test {
>     @CompileStatic
>     void printProgress(Map<Integer, Closure<String>> markers, int i) {
>         for (e in markers.entrySet()) {
>             if (i%e.key==0) { print e.value(i) ; break }
>         }
>     }
> }
> {code}
> Fails to compile with: {{Groovyc: [Static type checking] - Cannot find matching method java.util.Map$Entry#value(int). Please check if the declared type is right and if the method exists.}}
> The following fixes the problem, though it should not be necesarry to do explicit 'call'.
> {code}
> class Test {
>     @CompileStatic
>     void printProgress(Map<Integer, Closure<String>> markers, int i) {
>         for (e in markers.entrySet()) {
>             print e.value.call(i)
>         }
>     }
> }
> {code}
> For comparison, the following passes:
> {code}
> class Test {
>     @CompileStatic
>     void printProgress(Set<Closure<String>> markers, int i) {
>         for (e in markers) {
>             print e(i)
>         }
>     }
> }
> {code}



--
This message was sent by Atlassian Jira
(v8.3.4#803005)