tracker issue : CF-3482734

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

Bug in shorthand struct notation

| View in Tracker

Status/Resolution/Reason: Closed/Fixed/

Reporter/Name(from Bugbase): Adam Cameron / Adam Cameron (Adam Cameron)

Created: 01/17/2013

Components: Language

Versions: 10.0

Failure Type:

Found In Build/Fixed In Build: Final / 284722

Priority/Frequency: Normal / Few users will encounter

Locale/System: English / Windows 7 64-bit

Vote Count: 8

Problem Description:
Sometimes a line of code which precedes another line of code which happens to have short-hand struct notation appears to be skipped. In the example below (courtesy of Brad Wood... I myself never managed to come up with a repro case for this, although I have experienced it on two occasions), the var var1 line is skipped.

This can be replicated on all versions of CF from 9->10.0.7 (latest at time of writing)

I discuss another case of this on my blog here: http://adamcameroncoldfusion.blogspot.co.uk/2013/01/shorthand-struct-notation-is-still.html#comment-771074783

And have experienced it also on completely unrelated other code as well. So as edge-case as the example seems, it is a real issue which crops up.  Brad had encountered it too, obviously.

Steps to Reproduce:
<cfscript>
function callMe(){
    if(1){    // always true, so always runs
        var var1 = dummy();    // so var1 is definitely set
        var var2 = dummy(test={bar=''});
    }

    // Try to use var1
    var var3 = var1;    // error on this line: "Variable VAR1 is undefined."
}

function dummy(){
    return "";
}

callMe();
</cfscript>
Actual Result:
"Variable VAR1 is undefined."

Expected Result:
No error


Any Workarounds:
Don't use short-hand notation

-- 
Adam

----------------------------- Additional Watson Details -----------------------------

Watson Bug ID:	3482734

Keywords:
FixTested


External Customer Info:
External Company:  
External Customer Name: Adam Cameron.
External Customer Email:  
External Test Config: My Hardware and Environment details:

Attachments:

Comments:

This bug can take quite some time to figure out since it is quite unexpected and difficult to reproduce and simply results in a line of code appearing to not be run. Please fix.
Vote by External U.
16727 | January 17, 2013 01:45:45 PM GMT
shorthand struct (and array notation) is awesome from a code readability standpoint. I know it's been a work in progress since it was introduced. Please fix so we can have more confidently use it.
Vote by External U.
16728 | January 17, 2013 01:52:03 PM GMT
The behavior that this bug causes is completely unexpected
Vote by External U.
16729 | January 17, 2013 01:52:49 PM GMT
NB: array notation has the same problem. Just change the inline struct to be an inline array, and same error ensues. -- Adam
Comment by External U.
16722 | January 17, 2013 01:58:39 PM GMT
Unexpected and difficult to trace. Please correct.
Comment by External U.
16723 | January 17, 2013 02:03:47 PM GMT
Unexpected and difficult to trace. Please correct.
Vote by External U.
16730 | January 17, 2013 02:04:22 PM GMT
Please fix it so the shorthand struct works as expected.
Comment by External U.
16724 | January 17, 2013 02:16:18 PM GMT
Using a struct literal as an argument to a function with a named parameter causes such behavior. I use struct literals extensively as they are very expressive and save lines of code. Often they work fine in development, but when they go to heavier traffic environments and hold more data in memory, the bug crops up.
Vote by External U.
16731 | January 17, 2013 02:27:43 PM GMT
What they said! It's a hard one to trace
Vote by External U.
16732 | January 18, 2013 05:42:33 AM GMT
Please fix immediately. I've recently begun coding a brand new app which will be around for MANY YEARS, and it's disheartening to know I can't use the shorthand notation for complex variables such as new Query(parameters: ....) I'm so glad someone reproduced this bug, A few weeks ago it took me a couple hours to figure out what was going on because my aborts weren't even executing. I wound up declaring my complex variable in shorthand notation before my call to new Query(... , but I thought I was out of my mind for a while! Shorthand has had issues since 2007, it's time they work 100% perfectly. Also, I believe that when this situation arises, surrounding BLOCKS are affected by this bug (i.e. transactions don't roll back, I can't remember the exact scenario (I was under a VERY TIGHT deadline so I was hauling just to make things work!), so you may wish to run some regression tests involving transaction blocks cflock and try/catch blocks.
Vote by External U.
16733 | January 21, 2013 01:45:52 PM GMT
still seeing this relating to this bug - slightly different effect, but seems heavily related https://bugbase.adobe.com/index.cfm?event=bug&id=CF-3345255
Comment by External U.
16725 | July 15, 2013 12:25:59 AM GMT
Oh dear god. Please fix this.
Vote by External U.
16734 | July 17, 2014 08:49:43 AM GMT
See https://bugbase.adobe.com/index.cfm?event=bug&id=CF-3790842 where I have found a similar issue.
Comment by External U.
16726 | July 21, 2014 01:06:40 PM GMT