groovy-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "M. Justin (JIRA)" <j...@apache.org>
Subject [jira] [Updated] (GROOVY-8340) Static compilation error with a method parameter containing an array in a type parameter
Date Thu, 05 Oct 2017 14:53:00 GMT

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

M. Justin updated GROOVY-8340:
------------------------------
    Summary: Static compilation error with a method parameter containing an array in a type
parameter  (was: Static compilation with a method parameter containing an array in a type
parameter)

> 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
>              Labels: generics
>
> A compilation error occurs when 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}



--
This message was sent by Atlassian JIRA
(v6.4.14#64029)

Mime
View raw message