tracker issue : CF-4205245

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

Fat arrow UDF incorrectly returns value with no return in curly braces

| View in Tracker

Status/Resolution/Reason: Closed/Fixed/Fixed

Reporter/Name(from Bugbase): Bradley W. / ()

Created: 09/24/2019

Components: Language, Closures

Versions: 2018

Failure Type: Data Corruption

Found In Build/Fixed In Build: Update 5 / CF2018U6

Priority/Frequency: Normal / Some users will encounter

Locale/System: / Platforms All

Vote Count: 1

Problem Description:

When a fat arrow function has curly braces around the body, ONLY an explicit return statement should return a value.  The implicit return behavior only applies to a function body with no curlies. 

This is following the standard JavaScript implementation of fat arrow functions:
https://stackoverflow.com/questions/35440265/curly-brackets-in-arrow-functions

Please fix this quickly as it will be a breaking change since fat arrows are already out now in update 5.

Steps to Reproduce:

{code:java}
<cfscript>
// Incorrectly returns 4.  Should be undefined since no explicit return statement is used inside of curlies
func = x =>  { x+1 }
writeDump( func(3) )
</cfscript>
{code}

Actual Result:

4

Expected Result:

undefined

Attachments:

Comments:

This is a critical bug that needs to be fixed or implementations of arrow functions cannot be considered "stable" without a fix for it.
Vote by Jonathan C.
31374 | September 24, 2019 07:03:55 PM GMT
Here's a set of tests that show all known bugs in Lucee and Adobe CF's fat arrow functions along with a reference implementation in JS where everything passes. https://github.com/bdw429s/CFML-lambda-fat-arrow-functions
Comment by Bradley W.
31384 | September 25, 2019 04:32:19 PM GMT
Hi All, This issue is fixed now. Please reach out to ColdFusion support @ [cfinstal@adobe.com|mailto:cfinstal@adobe.com] to get the patch. -Nimit
Comment by Nimit S.
31463 | September 29, 2019 05:32:49 PM GMT