tracker issue : CF-3135083

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

Cannot immediately invoke a function returned from a function

| View in Tracker

Status/Resolution/Reason: To Fix/Deferred/BugVerified

Reporter/Name(from Bugbase): Nathan Strutz / Nathan Strutz (Nathan Strutz)

Created: 03/12/2012

Components: Language

Versions: 2016,11.0,10.0,2018

Failure Type: Incorrect w/Workaround

Found In Build/Fixed In Build: Public Beta /

Priority/Frequency: Normal / Some users will encounter

Locale/System: English / Windows 7 SP1 64-bit

Vote Count: 1

Problem Description:
I would like to immediately invoke a function when it is returned from calling a function, but CF will not compile it.

Steps to Reproduce:
function function returnfunction(){
		var x = " with closure";
		return function(a="returnFunction default argument") {return a & x;};
	writeOutput( returnFunction()() );

Actual Result:
Throws a syntax error:
Invalid CFML construct found on line 34 at column 38.
ColdFusion was looking at the following text:

Expected Result:
I expect the returned function to be invoked immediately, due to the second set of parentheses (). This is counterintuitive because of the way structs and arrays are addressable immediately after a function call. For example:
struct function getStruct() {
		return {a:1,b:2,c:3};
	writeOutput( getStruct()["b"] );

This code works as expected and prints "2" and the same works for arrays. It just seems like I should be able to immediately invoke the returned function without setting an extra variable.

Any Workarounds:
Set a variable to the returned function and invoke that.

----------------------------- Additional Watson Details -----------------------------

Watson Bug ID:	3135083

External Customer Info:
External Company:  
External Customer Name: mrnate
External Customer Email:  
External Test Config: My Hardware and Environment details:



+1 yeah, this is fairly standard syntax for this sort of thing. Should work.
Vote by External U.
20132 | December 10, 2014 07:52:49 AM GMT
Pls reopen and fix.
Comment by External U.
20131 | December 10, 2014 07:52:58 AM GMT