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 2020/01/01 22:44:00 UTC

[jira] [Comment Edited] (GROOVY-9120) Anonymous class enclosing reference broken in 2.5.7

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

Eric Milles edited comment on GROOVY-9120 at 1/1/20 10:43 PM:
--------------------------------------------------------------

{{VariableScopeVisitor#checkVariableNameForDeclaration}} looks for a variable declaration for a given name.  When found, the scopes between the declaration and reference are updated with a local variable reference.  In your example, the second occurrence of "number" in {{numberSupplier()}} goes through a different path in {{checkVariableNameForDeclaration}}.

This block is missing something to prevent indicating that "number" is a class variable on subsequent visitations:
{code:java}
        VariableScope end = scope;
        scope = currentScope;
        while (scope != end) {
            if (end.isClassScope() ||
                    (end.isReferencedClassVariable(name) && end.getDeclaredVariable(name) == null)) {
                scope.putReferencedClassVariable(var); // gets here, but should not
            } else {
                scope.putReferencedLocalVariable(var);
            }
            scope = scope.getParent();
        }
{code}


was (Author: emilles):
{VariableScopeVisitor#checkVariableNameForDeclaration}} looks for a variable declaration for a given name.  When found, the scopes between the declaration and reference are updated with a local variable reference.  In your example, the second occurrence of "number" in {{numberSupplier()}} goes through a different path in {{checkVariableNameForDeclaration }}.

This block is missing something to prevent indicating that "number" is a class variable on subsequent visitations:
{code:java}
        VariableScope end = scope;
        scope = currentScope;
        while (scope != end) {
            if (end.isClassScope() ||
                    (end.isReferencedClassVariable(name) && end.getDeclaredVariable(name) == null)) {
                scope.putReferencedClassVariable(var); // gets here, but should not
            } else {
                scope.putReferencedLocalVariable(var);
            }
            scope = scope.getParent();
        }
{code}

> Anonymous class enclosing reference broken in 2.5.7
> ---------------------------------------------------
>
>                 Key: GROOVY-9120
>                 URL: https://issues.apache.org/jira/browse/GROOVY-9120
>             Project: Groovy
>          Issue Type: Bug
>    Affects Versions: 2.5.7
>            Reporter: Romain Manni-Bucau
>            Assignee: Eric Milles
>            Priority: Major
>
> Follow up ticket of "2.5.7 regression with references?" mail.
> Using a ref defined outside an anonymous class frol the inner class is considered typed as "Reference" making it impossible to use in any java method now. It was working fine in 2.5.6.
> There is an example referenced in the dev list mail but it should be straight forward to reproduce.



--
This message was sent by Atlassian Jira
(v8.3.4#803005)