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/12/19 19:11:00 UTC

[jira] [Commented] (GROOVY-7799) Extended generic types with var args isn't compiled if they contains in different files

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

Eric Milles commented on GROOVY-7799:
-------------------------------------

In order for types to be discoverable from their source units, they must use Java-like naming.  For your example, "interface EE" needs to be in file "EE.groovy" and "class AB" needs to be in "AB.groovy".  With that small change, the compiler can find the source units and has handling for resolving via https://github.com/apache/groovy/pull/1664/commits/3831eb20b0bf183af9fac6ea036196d91a03880e

> Extended generic types with var args isn't compiled if they contains in different files
> ---------------------------------------------------------------------------------------
>
>                 Key: GROOVY-7799
>                 URL: https://issues.apache.org/jira/browse/GROOVY-7799
>             Project: Groovy
>          Issue Type: Bug
>          Components: Compiler
>    Affects Versions: 2.4.6
>         Environment: Oracle JRE 1.8_66
>            Reporter: Ilya Kuchmin
>            Assignee: Eric Milles
>            Priority: Major
>             Fix For: 4.0.0-rc-2
>
>
> Hi
> I created two files.
> {code:title=A.groovy|borderStyle=solid}
> package example;
> interface EE {
> }
> interface A<T extends EE> {
>     A<T> method(T args)
>     A<T> method(T[] args)
>     A<T> method(Collection<T> args)
> }
> class AB<T extends EE> implements A<T> {
>     @Override
>     AB<T> method(T args) {
>         return null
>     }
>     @Override
>     AB<T> method(T[] args) {
>         return this
>     }
>     @Override
>     AB<T> method(Collection<T> args) {
>         return this
>     }
> }
> {code}
> {code:title=ABC.groovy|borderStyle=solid}
> package example;
> class ABC<T extends EE> extends AB<T> {}
> {code}
> If you would like get bug that you should compile A.groovy and then compile ABC.groovy. For second file you should use compiled classes from file A.groovy. For second file compile throw exception: 
> {noformat}
> org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
> ABC.groovy: 3: Can't have an abstract method in a non-abstract class. The class 'example.ABC' must be declared abstract or the method 'example.A method(java.lang.Object[])' must be implemented.
>  @ line 3, column 1.
>    class ABC<T extends EE> extends AB<T> {}
>    ^
> 1 error
> {noformat}
> I can remove var args methods or replace "T extends EE" on T. It is workaround for compiler. Code will be compiled.



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