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-307) Variable redeclaration option
Date Tue, 01 Oct 2019 12:14:00 GMT

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

Dmitri Blinov commented on JEXL-307:
------------------------------------

Right now we have three scopes for a variable - context scope, global scope and function scope.
Context variables reside in JexlContext, global variables are defined during script evaluation,
and the last ones are defined within lambdas/functions as parameters or local variables. Introduction
of another scope - I would call it a *block scope*, is an interesting idea, but I think it
can be split off as a separate task. There are many things to consider, as whether to introduce
a separate keyword, for example {{let}}, for this, or if we can reuse {{var}}. Another consideration
is compatibility. We are get used to context and global scope variables. I think we should
not restrict assignments of undefined context variables as it breaks compatibility in many
ways. For example, now it is legal to use {{for (x : items)...}}, which may create a context
variable etc etc.

As a starter, we could solve more simple task, as whether or not to allow variable redefinition
within the global scope or the function scope. For example, the following constructs should
be prevented, during runtime, if variable redeclaration option is switched off:
{code:java}var c = 157; ...; var c = 42; {code} or 
{code:java}
var c = 157; {var c = 42; ...}
{code}
or
{code:java}
var c = 157; for (var c : items) ...
{code}
or
{code:java}
function(c) {var c = 157; ...}
{code}
or even
{code:java}
var c = 42; function(x) {var c = 157; ...}
{code}
The following constructs should be OK
{code:java}
var c = 157; if (false) {var c = 42; ...}
{code}
as well as
{code:java}
if (x) {var c = 42; ...} else {var c = 157; ...}
{code}

> Variable redeclaration option
> -----------------------------
>
>                 Key: JEXL-307
>                 URL: https://issues.apache.org/jira/browse/JEXL-307
>             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
(v8.3.4#803005)

Mime
View raw message