tracker issue : CF-4205517

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

Undefined Variable Thrown on Function Return

| View in Tracker

Status/Resolution/Reason: Closed/Withdrawn/CannotReproduce

Reporter/Name(from Bugbase): Joshua B. / ()

Created: 10/22/2019

Components: Language, Struct Functions

Versions: 2018

Failure Type: Incorrect w/Workaround

Found In Build/Fixed In Build: 2018.0.05.315699 / NA

Priority/Frequency: Normal / Unknown

Locale/System: English / Win 2016

Vote Count: 1

Problem Description: Running the provided code throws an undefined variable error, even though the variable is declared on the line above the return.

Steps to Reproduce:
{code}
<cffunction name="poc" access="public" returntype="struct">
    <cfif true>
        <cfset asdf = 1>
        <cfreturn { amount = asdf }>
    <cfelse>
        <cfreturn { amount = 2 }>
    </cfif>
</cffunction>

<cfoutput>#serializeJSON(poc())#</cfoutput>
{code}

Actual Result: Error thrown: Variable ASDF is undefined. <br>The error occurred on line 4.

Expected Result: {"AMOUNT":1}

Any Workarounds: No errors occur when any of the following changes are made:
* The function is changed to return numeric and line 4 is changed to <cfreturn asdf>.
* A separate variable is used to build the struct. <cfset output = { amount = asdf }><cfreturn output> works.
* Swapping lines 2 and 3, which moves the cfset outside of the cfif.
* Removing the cfelse (lines 5 and 6).

Attachments:

Comments:

Same error on Coldfusion 2016. The same workarounds solve the problem.
Comment by Danny R.
31710 | November 03, 2019 12:39:03 AM GMT
We are also seeing this bug in production.
Vote by Mark P.
31807 | November 12, 2019 07:41:41 PM GMT
Hi Joshua, I tried running the code in the latest update of CF2018 and couldn't find the issue? Can you please try running the code in latest update or you can even try in [https://cffiddle.org/]  and let us know about you r finding?
Comment by Mukesh K.
31904 | December 02, 2019 09:55:31 AM GMT
Hi Joshua, I am not able to reproduce the bug in latest update of both CF2016 and CF2018.  If you still facing the issue please email with code snippet to me at [mukumar@adobe.com.|mailto:mukumar@adobe.com.] Closing the bug as of now.   Regards, Mukesh 
Comment by Mukesh K.
33325 | March 30, 2020 04:33:04 AM GMT