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

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

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

JIRA jira@apache.org
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)