title: groovy: variable scope in closures in the super class (MissingPropertyException)
body: <p>I have the impression that closures run as the actual class being called (instead of the implementing super class) and thus break when some variables are not visible (e.g. private in the super class). </p>
  
  <p>For example</p>
  
  <pre><code>package comp.ds.GenericTest2
  
  import groovy.transform.CompileStatic
  
  @CompileStatic
  class ClosureScopeC {
          private List&lt;String&gt; list = new ArrayList&lt;String&gt;()
          private int accessThisPrivateVariable = 0;
  
          void add(String a) {
                  list.add(a)
                  println("before ${accessThisPrivateVariable} ${this.class.name}")
                  // do something with a closure
                  list.each {String it -&gt;
                          if (it == a) {
                                  // accessThisPrivateVariable belongs to ClosureScopeC
                                  accessThisPrivateVariable++
                          }
                  }
                  println("after ${accessThisPrivateVariable}")
          }
  }
  
  // this works fine
  a = new ClosureScopeC()
  a.add("abc")
  a.add("abc")
  
  // child class
  class ClosureScopeD extends ClosureScopeC {
          void doSomething(String obj) {
                  this.add(obj)
          }
  }
  
  b = new ClosureScopeD()
  
  // THIS THROWS groovy.lang.MissingPropertyException: No such property: accessThisPrivateVariable for class: comp.ds.GenericTest2.ClosureScopeD
  b.doSomething("abc")
  </code></pre>
  
  <p>The last line throws a MissingPropertyException: the child class calls the "add" method of the super class, which executes the "each" closure, which uses the "accessThisPrivateVariable". </p>
  
  <p>I am new to groovy, so I think there must be an easy way to do this, because otherwise it seems that closures completely break the encapsulation of the private implementation done in the super class ... this seems to be a very common need (super class implementation referencing its own private variables)</p>
  
  <p>I am using groovy 2.1.3</p>