[jira] [Updated] (GROOVY-8839) Static compilation and array type parameter causing compile error

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

[jira] [Updated] (GROOVY-8839) Static compilation and array type parameter causing compile error

JIRA jira@apache.org

     [ https://issues.apache.org/jira/browse/GROOVY-8839?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Eric Milles updated GROOVY-8839:
--------------------------------
    Fix Version/s: 2.5.0

> Static compilation and array type parameter causing compile error
> -----------------------------------------------------------------
>
>                 Key: GROOVY-8839
>                 URL: https://issues.apache.org/jira/browse/GROOVY-8839
>             Project: Groovy
>          Issue Type: Bug
>    Affects Versions: 2.4.15
>            Reporter: Eric Milles
>            Priority: Major
>             Fix For: 2.5.0
>
>         Attachments: Gr8.zip
>
>
> This seems related to GROOVY-8342 (and possibly GROOVY-8638 and GROOVY-7985).  When using an array in a generics parameter, I get static compilation errors for return of a map and also for assignment of return value to a variable.
> {code:java}
> package r;
> public class ResultHandle {}
> {code}
> {code:groovy}
> package p
> import groovy.transform.CompileStatic
> import r.ResultHandle
> @CompileStatic
> class Issue {
>   protected Map<String, ResultHandle[]> getResultsByType() {
>     Map<String, ResultHandle[]> resultsByType = [:]
>     // populate resultsByType
>     return resultsByType
>   }
> }
> {code}
> When I build using Ant, I get the following error:
> {code}
> Buildfile: ...\Gr8\build.xml
> -init:
> -compile:
>     [mkdir] Created dir: ...\Gr8\ant\JavaClasses
>   [compile] Compiling 2 source files to ...\Gr8\ant\JavaClasses
>   [compile] org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
>   [compile] ...\Gr8\src\main\bugs\Groovy1234.groovy: 12: [Static type checking] - Incompatible generic argument types. Cannot assign java.util.LinkedHashMap <java.lang.String, [Lr.ResultHandle;> to: java.util.Map <String, ResultHandle[]>
>   [compile]  @ line 12, column 12.
>   [compile]        return resultsByType
>   [compile]               ^
>   [compile] 1 error
> BUILD FAILED
> {code}
> Additionally, I would get an error if I assigned the result of the method to a typed variable, like this: {{Map<String, ResultHandle[]> resultsByType = getResultsByType()}}



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