Details
Assignee
Michael OffnerMichael OffnerReporter
Brad WoodBrad WoodPriority
NewLabels
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
Details
Details
Assignee
Michael Offner
Michael OffnerReporter
Brad Wood
Brad WoodPriority
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
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!