Phaninra created GROOVY-10472:
---------------------------------

             Summary: @AutoImplement is failing when covariant returns are 
involved
                 Key: GROOVY-10472
                 URL: https://issues.apache.org/jira/browse/GROOVY-10472
             Project: Groovy
          Issue Type: Bug
          Components: Compiler
            Reporter: Phaninra


`@AutoImplement` is failing when (Java) covariant returns are involved. 

 

Copy the following into GroovyConsole and hit run to reproduce the error.

 

 
{code:java}
import groovy.transform.*@CompileStatic

interface Super {
    Iterable findAll()
}

@CompileStatic
interface Sub extends Super {
    List findAll() // a List instead of an Iterable
}

@AutoImplement
@CompileStatic
class ThisClassFails implements Sub, Super {} {code}
 

 

Error will look like 

 
{code:java}
1 compilation error:

The return type of java.lang.Iterable findAll() in ThisClassFails is 
incompatible with java.util.List in Sub
. At [14:1]  at line: 14, column: 1 {code}
 

Refs:

- Real life example: 
[https://docs.spring.io/spring-data/jpa/docs/current/api/org/springframework/data/jpa/repository/JpaRepository.html]
 Look at all variations of `findAll` methods in that interface and super - some 
use Iterable and some use List. 

- Covariant return type : https://www.javatpoint.com/covariant-return-type

 

 



--
This message was sent by Atlassian Jira
(v8.20.1#820001)

Reply via email to