[ https://issues.apache.org/jira/browse/JEXL-287?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Henri Biestro reopened JEXL-287: -------------------------------- Found regression case related to safe navigation. > Wrong resolution of local variables > ----------------------------------- > > Key: JEXL-287 > URL: https://issues.apache.org/jira/browse/JEXL-287 > Project: Commons JEXL > Issue Type: Bug > Affects Versions: 3.1 > Reporter: Dmitri Blinov > Assignee: Henri Biestro > Priority: Major > > Consider the following example > {code:java} > x = 1; if (false) var x = 2; x > {code} > In this example the {{null}} is returned, which is the value of uninitialized > local variable {{x}}. The expected behaviour is to return {{1.}} > The reason is the variable declaration is a *statement*, so one can expect > that, as a statement, it should be evaluated according to its position within > the script structure. > The suggestion is to move the {{Scope.declareVariable()}} call from parse > time to interpretation time. Also, the resolution whether an identifier > inside the script referes to the local variable or to the contextual variable > should be moved from parse time to the interpretation time. > I think we can also reconsider the variable resolution during a variable > initialization: > {code:java} > sum = 0; var sum = sum + 1{code} > As of now, Jexl evaluates the local variable {{sum}} as {{1}}, as it > considers the {{sum+1}} an expression referencing the local variable {{sum}}, > which is, sort of, pointless. We can change this to referencing a contextual > variable instead, so that the result would be {{2}}. It can be useful in > plain-vanilla Jexl (without an access differentiator between local and > contextual variables) to allow one to initialize a local variable {{foo}} > with the value of contextual variable {{foo}} without using temporary > variable. -- This message was sent by Atlassian JIRA (v7.6.3#76005)