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

Closure inside an anonymous class uses wrong outside class instance with @CS

    Details

      Description

      This bug only occurs with @ComplieStatic

       Affects 2.4/2.5/3.0

       

      @CompileStatic
      class GroovyTest {
      
          private String foo
      
          void test() {
              new Runnable() {
                  void run() {
                      def c = {
                          foo
                      }
                      c()
                  }
              } .run()
          }
      
          static void main(String ...args) {
              new GroovyTest().test()
          }
      }
      

      Crash:

      Exception in thread "main" java.lang.ClassCastException: com.test.spring4mvc.controller.GroovyTest$1 cannot be cast to com.test.spring4mvc.controller.GroovyTest
          at com.test.spring4mvc.controller.GroovyTest$1$_run_closure1.doCall(GroovyTest.groovy)
          at com.test.spring4mvc.controller.GroovyTest$1$_run_closure1.call(GroovyTest.groovy)
          at com.test.spring4mvc.controller.GroovyTest$1.run(GroovyTest.groovy:16)
          at com.test.spring4mvc.controller.GroovyTest.test(GroovyTest.groovy:11)
          at com.test.spring4mvc.controller.GroovyTest.main(GroovyTest.groovy:22)
      

        Attachments

          Activity

            People

            • Assignee:
              paulk Paul King
              Reporter:
              wxiaoguang Xiaoguang Wang
            • Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: