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

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

Options are OK. The test case to illustrate the problem is this
{code:java}
    @Test
    public void testLexical6a1() throws Exception {
        String str = "i = 0; { var i = 32; }; i";
        JexlFeatures f = new JexlFeatures();
        f.lexical(true);
        JexlEngine jexl = new JexlBuilder().strict(true).features(f).create();
        JexlScript e = jexl.createScript(str);
        JexlContext ctxt = new MapContext();
        Object o = e.execute(ctxt);
        Assert.assertEquals(0, o);
    }{code}
The above test case fails with - variable is not defined. I understand the 
intention was good - to check for variables that are out of scope. But in 
practice it has become a severe restriction, with no way to disable.

Compare it with existing test case, which is OK and is an example of what I 
wish we could somehow achieve with lexical *feature* enabled.
{code:java}
    @Test
    public void testLexical6a() throws Exception {
        String str = "i = 0; { var i = 32; }; i";
        JexlEngine jexl = new JexlBuilder().strict(true).lexical(true).create();
        JexlScript e = jexl.createScript(str);
        JexlContext ctxt = new MapContext();
        Object o = e.execute(ctxt);
        Assert.assertEquals(0, o);
    } {code}
I'm not in favor of creating as much additional features as possible. If we 
could just *align* behaviour of lexical feature with that of lexical option, 
there would be no need for a new feature to disable that variable check.

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

Reply via email to