tracker issue : CF-3647489

select a category, or use search below
(searches all categories and all time range)
Title:

Explicit Local variable for closure should work out of its own localscope object, instead of parents localscope.

| View in Tracker

Status/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:

@Andrew, you have to be focused and tell exactly what the issue is. If you keep rambling and keep going in all the directions without actually mentioning what exactly is the bug, it does not help anyone. May be you should gather your thoughts and then go about logging the bug that tells exactly what the bug is. If I understand the bug correctly, the bug is - Closure does not allow a variable with same name in the Closure and in the enclosing function. Is that correct? If I got that right, that's like a treasure hunt :-).
Comment by Rupesh K.
14306 | October 08, 2013 12:25:23 PM GMT
I agree with you *again* Rupesh. It's just easier if the editorial content is removed, and a simple demonstration of the error is presented, with the only narrative being an explanation of the code or situation. Also Andrew: just raise one issue per ticket! There's two issues in this one ticket. Poor form. (yeah, sure, I always post editorial content with my bug tickets, but I also I think first succinctly describe the issue in as unambiguous a fashion as possible). -- Adam
Comment by External U.
14307 | October 08, 2013 05:16:45 PM GMT
No Rupesh it is along the lines of the original bug which you closed as Not wirth the effort. There is a serious issue when it comes to scopes. As per the original bug, I have since provided more samples even from your own documentation on how to use scopes inside closures and there is nothing in the docs except that one where I cam across the owner scope. for example the closure, is supposed to have access to all inner variables defined in the closure as well as outer variables. And yet if you reference them via there scope you can't access them. Or I you can cross contaminate variables because ColdFusion appears to not reference them via a correct scope. So while there is no scope for closures, we are finding that variables and accessing them are inconsistent in ColdFusion. For example the ColdFusion docs and best practices is to always scope variables and yet here is a case where there is no such thing as a scope. So your Not worth the Effort, from the original bug now shows that there is more to this problem than you care to admit Rupesh.
Comment by External U.
14308 | October 08, 2013 08:27:05 PM GMT