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: To Track//PRNeedInfo

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

Created: 10/22/2019

Components: Functions, Structures

Versions: 2018

Failure Type: Incorrect w/Workaround

Found In Build/Fixed In Build: 2018.0.05.315699 /

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