Lucee grabs wrong variable with same name from another scope in some cases

Description

I haven't been able to get a super simple repro case of this as it seems to only happen in certain cases where the call stack includes several closures being called upstream. I have two repro cases which work 100% of the time. One of them is inside a TestBox spec and the other is inside a CommandBox Task Runner. (Both of these involve quite a few closures inside the framework that wrap the calling code.

CommandBox task runner (you can just put this code in a task.cfc and run it with "task run" from the CLI.

component { function run( foo='I come from arguments' ) { variables.foo='I come from variables variables'; // This works as expected print.line( variables.foo); // Wrong variable is printed! ( (f)=>print.line( variables.foo))(); } }

TestBox Spec. (Add this to a test suite and run it in your TestBox runner

component extends="testbox.system.BaseSpec" { function repro( foo='I come from arguments' ) { variables.foo='I come from variables variables'; // This works as expected dump( variables.foo); // Wrong variable is printed! ( (f)=>dump( variables.foo))(); } function run() { describe( "TEST", function() { it( "BOOM", function() { repro(); } ); } ); } }

In BOTH cases where we print variables.foo, it should print out as

I come from variables variables

But that's not what's happening.

❯ task run I come from variables variables I come from arguments

The first print.line( variables.foo ) is correct, but the second one which runs from inside closure is grabbing the wrong variable. It's printing out arguments.foo instead.

If I rename the function argument to something like foobar the issue goes away so this is some sort of issue with Lucee finding a variable of the same name in the arguments scope and using it which is odd since variables.foo is explicitly scoped so there should be no ambiguity!

Environment

None

Activity

Show:

Pothys - MitrahSoft 2 September 2021 at 10:01

I've checked this ticket and confirmed the issue happened in lucee latest version 5.3.9.4-SNAPSHOT too. While using a closure in UDF or another closure, using variable scope variable inside a closure (even using variables prefix) was incorrectly resolved by the UDF/parent closure argument scope variable with the same name. Seems ACF works fine.
I added a testcase to this ticket

Pull Request: https://github.com/lucee/Lucee/pull/1422

Details

Assignee

Reporter

Priority

Labels

New Issue warning screen

Before you create a new Issue, please post to the mailing list first https://dev.lucee.org

Once the issue has been verified, one of the Lucee team will ask you to file an issue

Affects versions

Created 1 September 2021 at 14:16
Updated 8 July 2022 at 14:54

Flag notifications