tracker issue : CF-4199900

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

[ANeff] ER for: UDF arguments for simple value types to coerce the value's type

| View in Tracker

Status/Resolution/Reason: Closed/Withdrawn/AsDesigned

Reporter/Name(from Bugbase): Aaron Neff / Aaron Neff ()

Created: 10/03/2017

Components: Functions

Versions: 2016

Failure Type: Enhancement Request

Found In Build/Fixed In Build: CF 2016 /

Priority/Frequency: Normal /

Locale/System: /

Vote Count: 1

This ER is for: UDF arguments for simple value types to coerce the value's type

Example (using a "date" argument - but same would apply to any simple value type argument):

  tomorrow = now() + 1;
  function doStuff(required date someDate) {//Since the type is "date" here, then the value's type should be coerced to coldfusion.runtime.OleDateTime
    writeOutput(ARGUMENTS.someDate.getClass().getName() & ' ' & isValid("datetime_object", ARGUMENTS.someDate));
	//Actual Result: java.lang.Double NO
	//Expected Result: coldfusion.runtime.OleDateTime YES
	writeOutput(ARGUMENTS.someDate.year());//throws " The year method was not found."

Issue: Per Adam's suggestion, if CF can coerce a UDF argument's value to match the argument's type, it should actually do the coersion.

Then, within the UDF, the appropriate member functions for that value's type can be used. Ex: In the above, there would be no error thrown when calling ARGUMENTS.someDate.year()



ARGUMENTS.someDate.year() will not work because someDate passed to doStuff() is a Double(Numeric). We don't have date functions available on a numeric. This is the same behavior in 2016 as well. Changing this behavior will break backward compatibility.
Comment by Vijay M.
27540 | April 18, 2018 12:01:56 PM GMT
Hi Adobe, I see this is "To Test / AsDesigned'. Does that mean this feature won't be implemented? Thanks!, -Aaron
Comment by Aaron N.
27541 | April 25, 2018 08:52:51 AM GMT
Hi Vijay, Thanks for making your comment visible. What backward-compat issue? If argument type "date" allows a value thru that cannot be trusted as a date, then CF has a big problem. ARGUMENTS.someDate.year() should never throw an exception here! B/c argument type is "date"! I don't know what Adobe doesn't understand here. This is basic language design. A function argument accepts a specific type. Thus, within the function, the value should be fully usable as that type. Thanks!, -Aaron
Comment by Aaron N.
27542 | April 26, 2018 03:53:46 AM GMT
The issue is CF's trying to weakly enforce a semi-strict typing rule when using member functions. These work: 1) date member functions work on string 2) numeric member functions work on string, and vice-versa These fail: 1) string member functions fail on string 2) numeric member functions fail on date, and vice-versa It's a mixed-bag. And it's rearing its head in situations like above (i.e. a simple value passes thru an argument of type X, but doesn't have type X's member functions). That makes developers think twice before using a new feature (ex: like member functions). B/c the feature may or may not always work. Thanks!, -Aaron
Comment by Aaron N.
27543 | April 26, 2018 03:58:30 AM GMT
Aaron,  Now() + 1 results in a double value, and not a date. isDate too returns NO for this value.  A function that accepts date also accepts numerics as an exception. We have the option of throwing an exception, but doing that now would probably break code.     
Comment by Immanuel N.
27727 | May 09, 2018 12:02:38 PM GMT