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 2020/08/10 13:55:00 UTC

[jira] [Resolved] (GROOVY-7843) Trait method calling closure cannot be inherited while using CompileStatic

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

Eric Milles resolved GROOVY-7843.
---------------------------------
    Fix Version/s: 3.0.6
                   4.0.0-alpha-1
       Resolution: Fixed

> Trait method calling closure cannot be inherited while using CompileStatic
> --------------------------------------------------------------------------
>
>                 Key: GROOVY-7843
>                 URL: https://issues.apache.org/jira/browse/GROOVY-7843
>             Project: Groovy
>          Issue Type: Bug
>            Reporter: Arnaud CAVAILHEZ
>            Assignee: Eric Milles
>            Priority: Minor
>             Fix For: 4.0.0-alpha-1, 3.0.6
>
>
> A trait extending another and calling itself more than 3 times:
> {code}@CompileStatic
> trait UpperTrait {
>     void call(Closure body){
>         body()
>     }
> }{code}
> {code}@CompileStatic
> trait LowerTrait extends UpperTrait {
>     void threeCalls() {
>         call {
>             call {
>                 call {
>                 }
>             }
>         }
>     }
> }{code}
> Will generate a `ClassCastException` when called:
> {code}class ImplementsTrait implements LowerTrait {
> }
> new ImplementsTrait().threeCalls()
> {code}
> raises:
> {code}Caught: java.lang.ClassCastException: LowerTrait$Trait$Helper$_threeCalls_closure1 cannot be cast to UpperTrait
> java.lang.ClassCastException: LowerTrait$Trait$Helper$_threeCalls_closure1 cannot be cast to UpperTrait
> 	at LowerTrait$Trait$Helper$_threeCalls_closure1$_closure2.doCall(LowerTrait.groovy:9)
> etc..{code}



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