Details
-
Bug
-
Status: Closed
-
Major
-
Resolution: Fixed
-
2.1.9, 2.3.0, 2.4.0-rc-1
-
None
Description
The following code compiles:
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 {}
This also compiles:
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 {}
This will not compile:
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 $ 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 $