tracker issue : CF-4198389

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

Ternary operator doesn't short-circuit with implicit array/struct expressions

| View in Tracker

Status/Resolution/Reason: To Fix//Investigate

Reporter/Name(from Bugbase): Edward Keighley / Edward Keighley ()

Created: 03/06/2017

Components: Language, Expressions

Versions: 2016,11.0,10.0

Failure Type: Others

Found In Build/Fixed In Build: 11,0,10,300066 /

Priority/Frequency: Normal /

Locale/System: / Linux All

Vote Count: 7

Steps to Reproduce:

{code:java}
<cfscript>
a = 1; b = 1;
x = true ? [a++] : [b++];
writeDump(a);
writeDump(b);
writeDump(var=x, abort=true);
</cfscript>
{code}


Actual Result:
a==2 
b==2
x==[1]

Expected Result:
a==2
b==1
x==[1]

Any Workarounds:
a = 1; b = 1;
if(true) x=[a++]; else x=[b++];

Attachments:

Comments:

same failure on CF2016
Vote by Andrew C.
1131 | March 06, 2017 11:58:54 AM GMT
This bug still exists in CF2018. Both branches are still evaluated. I don't understand how such a fundamental flaw in the language can have been left unaddressed for more than a year.
Comment by Edward K.
29938 | November 16, 2018 11:22:48 AM GMT
Just seen this behaviour occur on ACF2018 u7. It is a bug with a nasty side effect. I don't get this side effect when using a ternary operator in Javascript or Lucee.
Comment by John W.
33279 | March 06, 2020 04:26:42 PM GMT
I know this was marked "ToFix", but could you up the priority? This seems like a Big Deal?
Comment by Mingo H.
33280 | March 06, 2020 04:52:52 PM GMT
Here's another example for you as you: https://cffiddle.org/app/file?filepath=ae665cdb-d6ee-4039-a3d3-aa6c9b5659d8/80ec6bea-989b-4d86-90f1-ce5753e84b77/164ea701-5c3d-42cb-9508-c689d5e44386.cfm {code} <cfscript> function foo() { var stack = []; return { a: function() { stack.append('a'); return 'a'; }, b: function() { stack.append('b'); return 'b'; }, doNotCallMe: function() { stack.append('BOOM!'); return 'doNotCallMe'; }, getStack: function() { return stack; } } } bar = foo(); choo = true ? { key: bar.a() } : { key: bar.doNotCallMe() }; x = bar.a(); y = bar.b(); z = bar.getStack(); writeDump({ choo: choo, // as expected x:x, // as expected y:y, // as expected z:z // note includes 'BOOM!' }) </cfscript> {code}
Comment by John W.
33281 | March 06, 2020 04:57:30 PM GMT