title: In groovy is it legal to reference private member variables from within a closure?
body: <p>Sample code which can easily be run in the GroovyConsole under groovy 2.4.4:</p>
  
  <pre class="lang-groovy prettyprint-override"><code>import groovy.transform.CompileStatic
  
  class Echo {
      public void text(String txt) {
          println txt
      }
  }
  
  class Test {
      private Echo echo = new Echo()
      @CompileStatic
      public void doStuff() {
          Closure c = {
              echo.text('hi')
          }
          c()        
      }
  }
  
  new Test().doStuff()
  </code></pre>
  
  <p>It fails with <code>java.lang.ClassCastException: Test$_doStuff_closure1 cannot be cast to Test</code>.</p>
  
  <p>Interestingly, if I remove the <code>@CompileStatic</code> annotation or make the member variable non-private it works as expected.</p>
  
  <p><strong>Edit:</strong> filed JIRA issue <a href="https://issues.apache.org/jira/browse/GROOVY-7558" rel="noreferrer">GROOVY-7558</a></p>