commons-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Henri Biestro (Jira)" <>
Subject [jira] [Commented] (JEXL-307) Variable redeclaration option
Date Wed, 02 Oct 2019 16:49:00 GMT


Henri Biestro commented on JEXL-307:

You nailed it, the local variable *shadow* scope is the issue.

However, after a local var definition scope block, allowing the same symbol (aka variable
name) to refer to a global might indeed _mask_ cases where the intent was to dereference
that local (out of scope / undefined). The analogy with Java local/instance variable applies;
it is very confusing indeed ! Good practise (and Java code checkers) frown upon shadowing
an instance var with a local for the very reason it is an easy bug generator.

 We do have the opportunity to be a bit strict and make a simple rule; no local symbol will
shadow a global var. Locals (defined or not) remain locals within a script.
 We may control that behaviour with another option flag (shadow) if this is really (really)
desirable keeping in mind simplicity trumps complexity and its surprises... 

> Variable redeclaration option
> -----------------------------
>                 Key: JEXL-307
>                 URL:
>             Project: Commons JEXL
>          Issue Type: New Feature
>    Affects Versions: 3.1
>            Reporter: Dmitri Blinov
>            Assignee: Henri Biestro
>            Priority: Minor
>             Fix For: 3.2
> As of now, JEXL allows a script writer to redeclare a local variable during script evaluation.
> {code:java}
> var a = 1; var a = 2;{code}
> This may lead to potential errors with misspelled names and clashed variables. Checking
for already defined variable is a common feature of many languages. This feature can be implemented
in JEXL as an additional option of JexlFeatures class, enabled by default, thus allowing compatibility
with existing code.

This message was sent by Atlassian Jira

View raw message