You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@groovy.apache.org by "Daniel Sun (JIRA)" <ji...@apache.org> on 2018/05/14 16:25:00 UTC

[jira] [Created] (GROOVY-8585) too many accessedVariable

Daniel Sun created GROOVY-8585:
----------------------------------

             Summary: too many accessedVariable
                 Key: GROOVY-8585
                 URL: https://issues.apache.org/jira/browse/GROOVY-8585
             Project: Groovy
          Issue Type: Bug
            Reporter: Daniel Sun


VariableExpression `str`  has endless accessedVariable, i.e. accessedVariable -> accessedVariable -> ... -> accessedVariable -> ...

{code:java}
        class Foo {
            def bar() {
                Object str = new Object()
                str = "str"
                str.toUpperCase() // here compile error
            }
        }
        println 123
{code}

VariableExpression Snippet
{code:java}
    public void setAccessedVariable(Variable origin) {
        checkVariable(origin);
        this.accessedVariable = origin;
    }

// the code added just for check
public static boolean checkVariable(Variable origin) {
        if (!(origin instanceof VariableExpression)) {
            return false;
        }

        int cnt = 0;
        for (VariableExpression ve = (VariableExpression) origin; ve != null; ve = (VariableExpression) ve.getAccessedVariable()) {
            cnt++;

            if (cnt > 100) {
                throw new RuntimeException("too many accessedVariable");
            }
        }

        return false;
    }
{code}





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