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 2018/10/10 15:21:00 UTC

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

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

Eric Milles edited comment on GROOVY-8839 at 10/10/18 3:20 PM:
---------------------------------------------------------------

If {{ResultHandle}} is in the same package the error subsides.  Also, it seems important that {{ResultHandle}} is a Java source and not a Groovy one.  I also tried a binary reference like {{Pattern}} from {{java.util.regex}} and that case did not have the error.


was (Author: emilles):
If {{ResultHandle}} is in the same package the error subsides.  Also, it seems important that {{ResultHandle}} is a Java source and not a Groovy one.

> 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
>
> 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)