Uploaded image for project: 'Groovy'
  1. Groovy
  2. GROOVY-7843

Trait method calling closure cannot be inherited while using CompileStatic

    XMLWordPrintableJSON

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Minor
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: 4.0.0-alpha-1, 3.0.6
    • Component/s: None
    • Labels:
      None

      Description

      A trait extending another and calling itself more than 3 times:

      @CompileStatic
      trait UpperTrait {
          void call(Closure body){
              body()
          }
      }
      @CompileStatic
      trait LowerTrait extends UpperTrait {
      
          void threeCalls() {
              call {
                  call {
                      call {
      
                      }
                  }
              }
          }
      }

      Will generate a `ClassCastException` when called:

      class ImplementsTrait implements LowerTrait {
      }
      new ImplementsTrait().threeCalls()
      

      raises:

      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..

        Attachments

          Activity

            People

            • Assignee:
              emilles Eric Milles
              Reporter:
              arnaud.cavailhez@gmail.com Arnaud CAVAILHEZ
            • Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: