[ 
https://issues.apache.org/jira/browse/GROOVY-9168?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Eric Milles updated GROOVY-9168:
--------------------------------
    Comment: was deleted

(was: The Runnable case compiles and runs fine in java.  The enclosing method 
for the AIC must be static initializer or something.

Here is the complete Java example:
{code:java}
public class Runner {
  public static void main(String[] args) {
    new Runner();
  }
  public Runner() {
    this(new Runnable() {
      @Override public void run() {
        System.out.println("ran");
      }
    });
  }
  public Runner(Runnable action) {
    action.run();
  }
}
{code}

{code}
  // Method descriptor #15 ()V
  // Stack: 3, Locals: 1
  public Runner();
     0  aload_0 [this]
     1  new Runner$1 [3]
     4  dup
     5  invokespecial Runner$1() [4]
     8  invokespecial Runner(java.lang.Runnable) [5]
    11  return
      Line numbers:
        [pc: 0, line: 6]
        [pc: 11, line: 11]
{code})

> Default Arguments: non-static inner class constructor call in default value 
> not supported
> -----------------------------------------------------------------------------------------
>
>                 Key: GROOVY-9168
>                 URL: https://issues.apache.org/jira/browse/GROOVY-9168
>             Project: Groovy
>          Issue Type: Bug
>    Affects Versions: 3.0.0-beta-1, 2.5.7
>            Reporter: Eric Milles
>            Priority: Major
>
> This is a variation of GROOVY-6777, GROOVY-6809 and GROOVY-7609.  A 
> constructor's parameter may not presently be defaulted  by a value expression 
> using a non-static inner class (including anon. inner).  This is likely 
> caused by the uninitialized "this" reference that is supplied to the 
> constructor of the non-static inner class.
> {code:groovy}
> // Error: Apparent variable 'this' was found in a static scope but doesn't 
> refer to a local variable, static field or class.
> class Outer {
>   class Inner {} // make this static and all is well
>   Outer(Inner inner = new Inner()) {
>   }
> }
> new Outer()
> {code}
> {code:groovy}
> class C {
>   C(Runnable runner = new Runnable() { void run() {} }) {
>     //                ^^^^^^^^^^^^^^ enclosing method not set and ...
>     this.runner = runner
>   }
>   Runnable runner
> }
> new C().runner.run()
> {code}



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)

Reply via email to