commons-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Dmitri Blinov (JIRA)" <j...@apache.org>
Subject [jira] [Commented] (JEXL-285) For statement variable may seem unaffected by iteration
Date Fri, 11 Jan 2019 16:42:00 GMT

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

Dmitri Blinov commented on JEXL-285:
------------------------------------

Though I don't like the initial idea of using contextual variables in 'for' statements, I
think we are breaking contract by this change. It is stated that {{for(x : items)}} should
use a contextual variable, because it was syntaxically specified to do so. After this change
it becomes unclear whether a contextual variable is used or a local one, because it is not
defined by syntax anymore.
Consider the following example:
{code}
x = 0; 
if (somecondition) {
   var x = 1;
}
for (x : items) {
}
// What is the value of contextual variable 'x' here?
{code}

If one is intentionally mixing local and contextual variables, one should be prepared to resolve
the visibilty shadowing by some other means, like using {{this.variable}} or something.

> 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)

Mime
View raw message