groovy-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Eric Milles (JIRA)" <j...@apache.org>
Subject [jira] [Comment Edited] (GROOVY-9058) each parameter type not correctly inferenced
Date Wed, 03 Apr 2019 15:42:00 GMT

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

Eric Milles edited comment on GROOVY-9058 at 4/3/19 3:41 PM:
-------------------------------------------------------------

In case of nested assignments like {{foo = bar = baz}} and {{foo(bar = baz)}}, the binary
expression should continue to infer to the type of the RHS.  So the above change does not
work.  I'm going to attempt a guard around {{storeType(leftExpression, resultType);}}, which
should only impact the inferred type of the variable or property.

*Please note the change suggested in the first comment should be enough to handle the exact
issue stated by the original submitter.  Everything after has been for a slightly altered
case where declared variable and assigned value types do not exactly align, for example if
the method {{bar}} in the original post returned {{List}} and not {{List<Object[]>}}.*


was (Author: emilles):
In case of nested assignments like {{foo = bar = baz}} and {{foo(bar = baz)}}, the binary
expression should continue to infer to the type of the RHS.  So the above change does not
work.  I'm going to attempt a guard around {{storeType(leftExpression, resultType);}}, which
should only impact the inferred type of the variable or property.

Please note the change suggested in the first comment should be enough to handle the exact
issue stated by the original submitter.  Everything after has been for a slightly altered
case where declared variable and assigned value types do not exactly align, for example if
the method {{bar}} in the original post returned {{List}} and not {{List<Object[]>}}.

> each parameter type not correctly inferenced
> --------------------------------------------
>
>                 Key: GROOVY-9058
>                 URL: https://issues.apache.org/jira/browse/GROOVY-9058
>             Project: Groovy
>          Issue Type: Bug
>          Components: Static compilation
>    Affects Versions: 2.5.6
>            Reporter: Mauro Molinari
>            Priority: Major
>
> Consider this Java class:
> {code:java}
> package test51;
> import java.util.List;
> public class Foo {
>     public List<Object[]> bar() { return null; }
> }{code}
>  and this Groovy class:
> {code:java}
> package test51
> import groovy.transform.CompileStatic
> @CompileStatic
> class Test51 {
>     protected void foo() {
>         List<Object[]> foo = new Foo().bar()
>         foo.each { row ->
>             def o = row[0]
>         }
>     }
>     
>     List bar() {
>     }
> }{code}
> This produces a compiler error because {{row}} is resolved as {{Object}} rather than
{{Object[]}}.
> A workaround is to declare {{row}} as {{Object[] row}} in the closure parameter list.



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)

Mime
View raw message