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

Daniel Sun commented on GROOVY-8340:
------------------------------------

Fixed on master; added a regression test in 
afd3361eb7cb0ec3bf606a5a7f8e1250c34fcce8 
(https://github.com/apache/groovy/commit/afd3361eb7cb0ec3bf606a5a7f8e1250c34fcce8).

> Static compilation error with a method parameter containing an array in a 
> type parameter
> ----------------------------------------------------------------------------------------
>
>                 Key: GROOVY-8340
>                 URL: https://issues.apache.org/jira/browse/GROOVY-8340
>             Project: Groovy
>          Issue Type: Bug
>          Components: Static compilation
>            Reporter: M. Justin
>            Assignee: Daniel Sun
>            Priority: Major
>              Labels: generics
>             Fix For: 7.0.0-alpha-1
>
>
> A compilation error occurs when using static compilation and attempting to 
> call a method with a parameterized argument that contains an array in the 
> type parameter.  The equivalent Java code has no issues.
> Here is a specific example:
> {code}@CompileStatic
> class ArrayGenericsIssue {
>   static void main(String[] args) {
>     Optional<Integer[]> o = Optional.of([1, 2, 3] as Integer[])
>     Integer firstFromArray = getFirstFromArray(o) //This fails to compile
>     println "First (array): $firstFromArray"
>   }
>   static <E> E getFirstFromArray(Optional<E[]> optional) {
>     return optional.get()[0]
>   }
> }{code}
> The error returned is:
> {code}Error:(16, 30) Groovyc: [Static type checking] - Cannot call 
> <E>ArrayGenericsIssue#getFirstFromArray(java.util.Optional 
> <[Ljava.lang.Object;>) with arguments [java.util.Optional 
> <[Ljava.lang.Integer;>{code}
> The expected behavior is that this code would compile and run successfully 
> with @CompileStatic enabled.
> Note that equivalent code with a non-array generic parameter works just fine:
> {code}
>   static void main(String[] args) {
>     Optional<List<Integer>> o = Optional.of([1, 2, 3])
>     Integer firstFromList = getFirstFromList(o) //This compiles just fine
>     println "First (list): $firstFromList"
>   }
>   static <E> E getFirstFromList(Optional<List<E>> optional) {
>     return optional.get()[0]
>   }
> {code}
> Additionally, there is no compilation issue if the value is cast to a raw 
> type:
> {code}Integer firstFromArray = getFirstFromArray((Optional) o2){code}
> For some context, I'm running into this issue when working with 
> [jOOQ|https://www.jooq.org/], as some of its API involves working with array 
> type parameters. 



--
This message was sent by Atlassian Jira
(v10.3.26#10030026)

Reply via email to