tracker issue : CF-3755175

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

returntype of "function" is not honored but is not prohibited per the documentation

| View in Tracker

Status/Resolution/Reason: To Fix//

Reporter/Name(from Bugbase): Brian Ghidinelli / Brian Ghidinelli (Brian Ghidinelli)

Created: 05/05/2014

Components: CFComponent

Versions: 10.0

Failure Type:

Found In Build/Fixed In Build: Final /

Priority/Frequency: Normal / All users will encounter

Locale/System: English / Windows 7 64-bit

Vote Count: 1

Problem Description:
When I specify a <cffunction> tag with a returntype of "Function" (for a component named Function.cfc), CF10 does not properly mark the object as a type "Function" preventing it from being accepted by other components which require the type to be "Function".

Function is not listed in the documentation as being prohibited:

https://wikidocs.adobe.com/wiki/display/coldfusionen/cffunction

Surprisingly, this happens whether or not "Disable CFC Type Check" is enabled in the Administrator.

Steps to Reproduce:

Create Function.cfc: 
<cfcomponent name="Function">
	
	<cffunction name="init" output="false" access="public" returntype="Function">
		<cfset this.foo = 1 />
		<cfreturn this />
	</cffunction>

	<cffunction name="getFoo" output="false" access="public" returntype="numeric">
		<cfreturn this.foo />
	</cffunction>

</cfcomponent>

Create test.cfm:
<cffunction name="takeFunction" output="false" access="public" returntype="any">
	<cfargument name="func" type="Function" required="true" />

	<cfreturn arguments.func.getFoo() />
</cffunction>

<cfset o = createObject("component", "Function").init() />

<cfoutput>#takeFunction(o)#</cfoutput>


Actual Result:
Error Occurred While Processing Request
The value returned from the init function is not of type Function.

The error occurred in C:/Users/brian/Documents/web/trunk-main/test.cfm: line 8
6 : </cffunction>
7 : 
8 : <cfset o = createObject("component", "Function").init() />
9 : 
10 : <cfoutput>#takeFunction(o)#</cfoutput>
Stack Trace
at cftest2ecfm710216492._factor4(C:/Users/brian/Documents/web/trunk-main/test.cfm:8) at cftest2ecfm710216492.runPage(C:/Users/brian/Documents/web/trunk-main/test.cfm:1) 

coldfusion.runtime.UDFMethod$InvalidReturnTypeException: The value returned from the init function is not of type Function.
	at coldfusion.runtime.UDFMethod$ReturnTypeFilter.invoke(UDFMethod.java:429)
	at coldfusion.runtime.UDFMethod$ArgumentCollectionFilter.invoke(UDFMethod.java:368)
	at coldfusion.filter.FunctionAccessFilter.invoke(FunctionAccessFilter.java:55)
	at coldfusion.runtime.UDFMethod.runFilterChain(UDFMethod.java:321)
	at coldfusion.runtime.UDFMethod.invoke(UDFMethod.java:220)
	at coldfusion.runtime.TemplateProxy.invoke(TemplateProxy.java:655)
	at coldfusion.runtime.TemplateProxy.invoke(TemplateProxy.java:444)
	at coldfusion.runtime.TemplateProxy.invoke(TemplateProxy.java:414)
	at coldfusion.runtime.CfJspPage._invoke(CfJspPage.java:2432)
	at cftest2ecfm710216492._factor4(C:\Users\brian\Documents\web\trunk-main\test.cfm:8)
	at cftest2ecfm710216492.runPage(C:\Users\brian\Documents\web\trunk-main\test.cfm:1)
        ...


Expected Result:
The number "1".


Any Workarounds:
* Rename CFC types to not be "Function"
* Update the CF10 documentation

However, it's worth noting that several libraries such as Transfer ORM have a "Function" component and depend on this to work.  Transfer works for me in production however it fails to run its own unit tests because of this issue.

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

Watson Bug ID:	3755175

External Customer Info:
External Company:  
External Customer Name: brianatvfive
External Customer Email:  
External Test Config: Windows 7, CF 10 Developer

Attachments:

Comments:

[subscribe] -- Adam ////////////////////
Vote by External U.
12319 | May 06, 2014 02:40:12 AM GMT
CFC init method will always return CFC instance irrespective of returnType specified. For any other CFC function returnType as "Function" is honored. (Comment added from ex-user id:sandeepp)
Comment by Adobe D.
12316 | May 12, 2014 05:44:22 AM GMT
Sandeep - did you try running my test case above? Can you explain why that error is acceptable?
Comment by External U.
12317 | July 11, 2014 04:55:29 PM GMT
The Problem here is that having the CFC with name "Function" and having "Function" as returnType creates ambiguity. So CF cannot resolve the returned value is a CFC and treats is as a function. We will get this updated in the documentation that such cases will not be supported. (Comment added from ex-user id:sandeepp)
Comment by Adobe D.
12318 | July 14, 2014 12:20:42 AM GMT