[jira] [Commented] (JEXL-285) For statement variable may seem unaffected by iteration

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

[jira] [Commented] (JEXL-285) For statement variable may seem unaffected by iteration

JIRA jira@apache.org

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

Henri Biestro commented on JEXL-285:
------------------------------------

After the declaration of a local variable, its symbol is always resolved as the local variable; local variables have global scope after their declaration and they do have precedence over contextual ones. In you example, the contextual 'x' is 0 ; 'x' is however solved as the local one (ie the last value of iteration). In other words, in a vanilla JEXL -'this' not pointing at the context - , there is no way to access a contextual variable whose symbol clashes with a local after its declaration.
No-one does clash intentionally contextual and local variables; these are mistake that cause much grief since forgetting the 'var' in the 'for' may result in incorrect iteration. The fix is actually enforcing the contract of variable resolution in the 'for' statement.

> For statement variable may seem unaffected by iteration
> -------------------------------------------------------
>
>                 Key: JEXL-285
>                 URL: https://issues.apache.org/jira/browse/JEXL-285
>             Project: Commons JEXL
>          Issue Type: Bug
>    Affects Versions: 3.1
>            Reporter: Henri Biestro
>            Assignee: Henri Biestro
>            Priority: Major
>             Fix For: 3.2
>
>
> When a 'for' loop uses a global variable (as in (for c: ...)), if a local variable with that name has been declared previously, the global variable is nevertheless used for iteration. Since the local variable is preferred during resolution in statements within the loop, the iteration does not change the variable value.



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