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: Open//

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: 0

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