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

Eric Milles commented on GROOVY-5961:
-------------------------------------

Thanks for the extra test cases.  They both fail for missing field "this$0", 
which is added by {{InnerClassVisitor}}:
{code:java}
    @Override
    public void visitClass(ClassNode node) {
        this.classNode = node;
        thisField = null;
        InnerClassNode innerClass = null;
        if (!node.isEnum() && !node.isInterface() && node instanceof 
InnerClassNode) {
            innerClass = (InnerClassNode) node;
            if (!isStatic(innerClass) && innerClass.getVariableScope() == null) 
{
                thisField = innerClass.addField("this$0", PUBLIC_SYNTHETIC, 
node.getOuterClass().getPlainNodeReference(), null);
            }
        }
{code}

I can update the condition; I think it just needs to check for "isAnonymous".

> Variable scope not checked properly for AIC in static method
> ------------------------------------------------------------
>
>                 Key: GROOVY-5961
>                 URL: https://issues.apache.org/jira/browse/GROOVY-5961
>             Project: Groovy
>          Issue Type: Sub-task
>          Components: Compiler
>    Affects Versions: 2.1.0
>            Reporter: Cédric Champeau
>            Priority: Major
>         Attachments: VariableScopeVisitor.java
>
>
> The following code will fail:
> {code}
> static void foo() {
>     new LinkedList() {
>         int index
>         Object get(int i) { super.get(index++) }
>     }
> }
> {code}
> The error is:
> {noformat}
> Apparent variable 'index' was found in a static scope but doesn't refer to a 
> local variable, static field or class. Possible causes:
> You attempted to reference a variable in the binding or an instance variable 
> from a static context.
> You misspelled a classname or statically imported field. Please check the 
> spelling.
> You attempted to use a method 'index' but left out brackets in a place not 
> allowed by the grammar.
>  at line: 5, column: 39
> {noformat}
> But obviously, {{index}} is not accessed from a static context here.



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

Reply via email to