You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@groovy.apache.org by "Eric Milles (JIRA)" <ji...@apache.org> on 2019/06/09 21:00:00 UTC

[jira] [Comment Edited] (GROOVY-9168) Default Arguments: non-static inner class constructor call in default value not supported

    [ https://issues.apache.org/jira/browse/GROOVY-9168?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16859562#comment-16859562 ] 

Eric Milles edited comment on GROOVY-9168 at 6/9/19 8:59 PM:
-------------------------------------------------------------

In the case of Outer/Inner, javac produces "error: cannot reference this before supertype constructor has been called" and ecj produces "No enclosing instance of type Outer is available due to some intermediate constructor invocation".  Could the groovyc error "Apparent variable 'this' was found in a static scope but doesn't refer to a local variable, static field or class." be made more specific?

Also, the javac error is indicated at the start of "new Inner" whereas the groovyc error is on line -1, column -1.  Error is creagted by {{StaticVerifier.visitConstructorOrMethod}}.


was (Author: emilles):
In the case of Outer/Inner, javac produces "error: cannot reference this before supertype constructor has been called" and ecj produces "No enclosing instance of type Outer is available due to some intermediate constructor invocation".  Could the groovyc error "Apparent variable 'this' was found in a static scope but doesn't refer to a local variable, static field or class." be made more specific?

> 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)