Title:
Explicit Local variable for closure should work out of its own localscope object, instead of parents localscope.
| View in TrackerStatus/Resolution/Reason: Closed/Fixed/
Reporter/Name(from Bugbase): Andrew Scott / Andrew Scott (Andrew Scott)
Created: 10/08/2013
Components: Core Runtime
Versions: 10.0
Failure Type:
Found In Build/Fixed In Build: Final / 288502
Priority/Frequency: Major / Most users will encounter
Locale/System: English / Win 2008 Server
Vote Count: 0
Problem Description:
Closures are confusing, the documentation for them is all over the place and needs to be in one place. That is problem number 1.
Problem number 2, is that there is not consistency with what ColdFusion defines as local variables.
For example the following code
component {
variables.member = 20;
private String function method() {
return "hello";
}
public string function publicMethod (String name) {
var localVar = member + 5;
var localVar2 = "Parameter: #name#";
return function() {
var localVar = "25";
return "#member# #name# #localVar# #localVar2# #method()#";
};
}
var sample = new A();
var closureVar = sample.publicMethod("Xavier");
writeDump(closureVar());
Should produce
20 Xavier 25 Parameter: Xavier hello
However, if we refactor the code to
public string function publicMethod (String name) {
local.localVar = member + 5;
local.localVar2 = "Parameter: #name#";
return function() {
local.localVar = "zzzzzz";
return "#member# #name# #local.localVar# #localVar2# #method()#";
};
}
We get an error Element LOCALVAR is undefined in LOCAL. And yet Rupesh, if we go back to the ColdFusion documentation, it clearly states that using either var localVar or local.localVar the variable is stored in the same scope.
The fact that ColdFusion is making a meal of scopes when it comes to closures, indicates that there is a major bug here.
If you read my blog post over at
http://www.andyscott.id.au/blog/interesting-closure-issues-within-coldfusion-10
You will also notice that the example I have provided there, screams variable contamination that should not be occurring.
In the original bug raised, which you never went back too. You will notice Not worth the effort, then you mark it as user error.... Is there a chance you will see an issue here, and actually fix it?
Steps to Reproduce:
Actual Result:
Expected Result:
Any Workarounds:
----------------------------- Additional Watson Details -----------------------------
Watson Bug ID: 3647489
External Customer Info:
External Company:
External Customer Name: ascott67
External Customer Email:
External Test Config: My Hardware and Environment details:
Attachments:
Comments: