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 2021/10/11 17:25:01 UTC

[jira] [Resolved] (GROOVY-6408) Problem With @CompileStatic And Typed Collections

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

Eric Milles resolved GROOVY-6408.
---------------------------------
    Fix Version/s: 4.0.0-alpha-3
       Resolution: Fixed

See GROOVY-6912, GROOVY-7106, GROOVY-7128, GROOVY-7274, GROOVY-7468, GROOVY-8909, and GROOVY-9844

> Problem With @CompileStatic And Typed Collections
> -------------------------------------------------
>
>                 Key: GROOVY-6408
>                 URL: https://issues.apache.org/jira/browse/GROOVY-6408
>             Project: Groovy
>          Issue Type: Bug
>          Components: Static Type Checker
>    Affects Versions: 2.1.9, 2.3.0, 2.4.0-rc-1
>            Reporter: Jeff Brown
>            Assignee: Eric Milles
>            Priority: Major
>             Fix For: 4.0.0-alpha-3
>
>
> The following code compiles:
> {code:borderStyle=solid|title=Demo.groovy}
> @groovy.transform.CompileStatic
> class Demo {
>     def test(Listener listener1) {
>         def listener2 = new DefaultListener()
>         List<Listener> listeners = [listener1, listener2]
>     }
> }
> interface Listener {}
> class DefaultListener implements Listener {}
> {code}
> This also compiles:
> {code:borderStyle=solid|title=Demo.groovy}
> @groovy.transform.CompileStatic
> class Demo {
>     def test(Listener listener1) {
>         def listener2 = new DefaultListener()
>         List<Listener> listeners = [listener1]
>     }
> }
> interface Listener {}
> class DefaultListener implements Listener {}
> {code}
> This will not compile:
> {code:borderStyle=solid|title=Demo.groovy}
> @groovy.transform.CompileStatic
> class Demo {
>     def test(Listener listener1) {
>         def listener2 = new DefaultListener()
>         List<Listener> listeners = [listener2]
>     }
> }
> interface Listener {}
> class DefaultListener implements Listener {}
> {code}
> {noformat}
> staticcompiledcollection $ groovy -version
> Groovy Version: 2.1.9 JVM: 1.6.0_51 Vendor: Apple Inc. OS: Mac OS X
> staticcompiledcollection $ 
> staticcompiledcollection $ cat Demo.groovy 
> @groovy.transform.CompileStatic
> class Demo {
>     def test(Listener listener1) {
>         def listener2 = new DefaultListener()
>         List<Listener> listeners = [listener2]
>     }
> }
> interface Listener {}
> class DefaultListener implements Listener {}
> staticcompiledcollection $ 
> staticcompiledcollection $ groovyc Demo.groovy 
> org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
> Demo.groovy: 5: [Static type checking] - Incompatible generic argument types. Cannot assign java.util.List <DefaultListener> to: java.util.List <Listener>
>  @ line 5, column 36.
>            List<Listener> listeners = [listener2]
>                                       ^
> 1 error
> staticcompiledcollection $
> {noformat}



--
This message was sent by Atlassian Jira
(v8.3.4#803005)