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: