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/17 15:44:00 UTC

[jira] [Updated] (GROOVY-7714) Trait with static generic method and usage in different sub-project

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

Eric Milles updated GROOVY-7714:
--------------------------------
    Labels: trait traits  (was: )

> Trait with static generic method and usage in different sub-project
> -------------------------------------------------------------------
>
>                 Key: GROOVY-7714
>                 URL: https://issues.apache.org/jira/browse/GROOVY-7714
>             Project: Groovy
>          Issue Type: Bug
>    Affects Versions: 2.4.5
>            Reporter: Steinar Haugen
>            Priority: Major
>              Labels: trait, traits
>         Attachments: trait-bug.zip
>
>
> Bumped into a compilation error and created a minimal project to reproduce.
> It consists of a gradle project with two subprojects. The first subproject contains a trait and an implementing class. The second subproject contains a class that returns the implemening class. 
> See attached zip file for source code. 
> It consists of three source files:
> {code:title=sub1/src/main/groovy/sub1/MyTrait.groovy}
> package sub1
> trait MyTrait {
>     static <T extends MyTrait> T getMyTrait() {null}
> }
> {code}
> {code:title=sub1/src/main/groovy/sub1/MyTraitImpl.groovy}
> package sub1
> class MyTraitImpl implements MyTrait {
> }
> {code}
> {code:title=sub2/src/main/groovy/sub2/Producer.groovy}
> package sub2
> import sub1.MyTraitImpl
> class Producer {
>     MyTraitImpl produce() {
>         return null
>     }
> }
> {code}
> Building yields the following error message:
> Execution failed for task ':sub2:compileGroovy'.
> > BUG! exception in phase 'class generation' in source unit '/source/trait-bug/sub2/src/main/groovy/sub2/Producer.groovy' Type is null. Most probably you let a transform reuse existing ClassNodes with generics information, that is now used in a wrong context.
> If the source code in sub2 is moved to sub1, it compiles without error.
> If generics is removed from the method signature in MyTrait (i.e. changed to something like "static MyTrait getMyTrait()") it compiles without error.



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