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/03/12 18:57:00 UTC

[jira] [Comment Edited] (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=17300553#comment-17300553 ] 

Eric Milles edited comment on GROOVY-5881 at 3/12/21, 6:56 PM:
---------------------------------------------------------------

It is {{VariableScopeVisitor}} that detects an implicit-this variable-expression method call and replaces it with "vexp.call(args)".  This is not done for references to fields, properties or dynamic variables.  And property expressions like "this.name()" or in your case "e.value\(i)" are not transformed.

https://github.com/apache/groovy/blob/26806ea9b3a081908fa2e5a1d9240dd04bee2dce/src/main/java/org/codehaus/groovy/classgen/VariableScopeVisitor.java#L565


was (Author: emilles):
It is {{VariableScopeVisitor}} that detects an implicit-this variable-expression method call and replaces it with "vexp.call(args)".  This is not done for references to fields, properties or dynamic variables.  And property expressions like "this.name()" or in your case "e.value(i)" are not transformed.

https://github.com/apache/groovy/blob/26806ea9b3a081908fa2e5a1d9240dd04bee2dce/src/main/java/org/codehaus/groovy/classgen/VariableScopeVisitor.java#L565

> 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
>            Assignee: Eric Milles
>            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)