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

Cannot call Trait method from Closure when using static compilation

    XMLWordPrintableJSON

Details

    Description

      When running:

      test.groovy
      class X {
          Closure action = {}
      }
      
      trait T {
      
          void say(String text) {
              println text
          }
      
          @groovy.transform.CompileStatic
          X getX() {
              new X(action: {
                  say "Hello!"
              })
          }
      
      }
      
      class A implements T {
      }
      
      new A().x.action()
      

      The following exception is thrown:

      Caught: java.lang.ClassCastException: java.lang.Class cannot be cast to T
      java.lang.ClassCastException: java.lang.Class cannot be cast to T
      	at T$Trait$Helper$_getX_closure1.doCall(test.groovy:14)
      	at T$Trait$Helper$_getX_closure1.doCall(test.groovy)
      	at test.run(test.groovy:23)
      

      This is only happening on groovy 2.4.4. Removing the static compilation annotation or reverting to groovy version 2.4.3 makes the code work.

      The commit that is causing this problem seems to be: 1bbed25aa3a08bc0cb7e14e49a1e7c2b82f21a26

      Attachments

        Activity

          People

            emilles Eric Milles
            cesarizu César Izurieta
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Time Tracking

                Estimated:
                Original Estimate - Not Specified
                Not Specified
                Remaining:
                Remaining Estimate - 0h
                0h
                Logged:
                Time Spent - 0.5h
                0.5h