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

Fails at runtime with @CompileStatic and two nested with

    XMLWordPrintableJSON

Details

    Description

      Consider this class:

      package testgroovy
      
      import groovy.transform.CompileStatic
      
      @CompileStatic
      class Foobar {
          
          static class Foo {
              String aaa = 'aaa'
              String bbb = 'bbb'
          }
          
          static class Bar {
              String ccc = 'ccc'
          }
          
          Foo foo = new Foo()
          Bar bar = new Bar()
          
          void foobar() {
              foo.with {
                  bar.with {
                      println aaa
                      println bbb
                      println ccc
                  }
              }
          }
      
          static void main(String[] args) {
              new Foobar().foobar()
          }    
      }

      It fails at runtime with:

      Exception in thread "main" java.lang.ClassCastException: testgroovy.Foobar$Bar cannot be cast to groovy.lang.Closure
          at testgroovy.Foobar$_foobar_closure1$_closure2.doCall(Foobar.groovy:23)
          at testgroovy.Foobar$_foobar_closure1$_closure2.call(Foobar.groovy)
          at org.codehaus.groovy.runtime.DefaultGroovyMethods.with(DefaultGroovyMethods.java:369)
          at org.codehaus.groovy.runtime.DefaultGroovyMethods.with(DefaultGroovyMethods.java:316)
          at testgroovy.Foobar$_foobar_closure1.doCall(Foobar.groovy:22)
          at testgroovy.Foobar$_foobar_closure1.call(Foobar.groovy)
          at org.codehaus.groovy.runtime.DefaultGroovyMethods.with(DefaultGroovyMethods.java:369)
          at org.codehaus.groovy.runtime.DefaultGroovyMethods.with(DefaultGroovyMethods.java:316)
          at testgroovy.Foobar.foobar(Foobar.groovy:21)
          at testgroovy.Foobar.main(Foobar.groovy:31)

      It works fine if you remove @CompileStatic.

      Attachments

        Issue Links

          Activity

            People

              paulk Paul King
              mauromol Mauro Molinari
              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 - 20m
                  20m