tracker issue : CF-4204917

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

CFSCRIPT: UDF - Use of "Default" in first argument results in error.

| View in Tracker

Status/Resolution/Reason: Open//

Reporter/Name(from Bugbase): Bryon N. / ()

Created: 08/03/2019

Components: Language, CFSCRIPT

Versions: 2018

Failure Type: Incorrect w/Workaround

Found In Build/Fixed In Build: 2018.0.04.314546 /

Priority/Frequency: Normal / All users will encounter

Locale/System: English / Win 2016

Vote Count: 0

Problem Description:
In CFSCRIPT in a User Defined Function If the first argument contains "Default" then a run time error occurs.

This issue only exists on the first argument of each function. The second argument works fine with a default value.

Error returned: 
"The DEFAULT argument passed to the init function is not of type [argument name]."

Steps to Reproduce:
1) Create a function in cfscript that contains a default value. 
2) Call the function.

This always returns the error. It does not matter if it's in a CFC or CFM page. It occurs no matter the type defined.

Example:
<cfscript>
    function test(string myVariable default="" hint="This should define a default value for the argument"){ return this;	}
</cfscript>
<cfset test()>
<cfset test("a")>

Actual Result:
Error:
"The DEFAULT argument passed to the init function is not of type myVariable."
or
"The DEFAULT argument passed to the init function is not of type [argument name]."

ColdFusion is interpreting the argument and as type instead of the variable name.
The error only occurs on the first argument.

Expected Result:
The a default value should be created for the argument. 
The error should NOT occur. 
ColdFusion should not think the argument name is a type.

Any Workarounds:
Remove all default values and use param to define a default value.

Attachments:

Comments:

Hi Bryon, CF9's undocumented `default=""` syntax is unsupported in CF2018+. Supported CF9+ syntax is myVariable="": <cfscript> /** *@myVariable.hint "This should define a default value for the argument" */ function test(string myVariable=""){} </cfscript> Note: The fact that 'hint' seems to work in your example, is b/c CF supports user-defined metadata attributes: https://helpx.adobe.com/coldfusion/developing-applications/the-cfml-programming-language/extending-coldfusion-pages-with-cfml-scripting/defining-components-and-functions-in-cfscript.html (search for 'custom metadata) Hi Adobe, 1) I've filed CF-4204921 for the actual bug. 2) Script argument hint syntax is undocumented (doc bug). Can you please add an @arg.hint example to that doc (URL in above note), w/o me logging a separate ticket? Thanks!, -Aaron
Comment by Aaron N.
31098 | August 04, 2019 02:15:41 AM GMT
Thanks! Looks like we have lots of code to fix... I would still like to leave this ticket open or merge it with CF-4204921. because there's a pretty major compiler bug.
Comment by Bryon N.
31105 | August 06, 2019 03:53:09 PM GMT