http://coldfusion.com logo
#adobe
Title
# adobe
a

Adam Cameron

09/23/2022, 1:25 PM
Any reason this is not a bug in the spread operator implementation: https://trycf.com/gist/293eec9f7b0b611afc4dc00c8e1a7e3b/acf2021?theme=monokai
Copy code
args = ["I have not been updated", "not ", "", "ONE"]

//result = replace(...args) // <--- this should work, but errors with Parameter validation error for the REPLACE function. on line 4
result = udfReplace(...args)


function udfReplace(string, substring, replacement, scope) {
    writeDump(arguments)
    return replace(string, substring, replacement, scope)
}

writeDump(result)
r

Rodney

09/23/2022, 1:44 PM
Odd. Using the member function works.
Copy code
testString = "I have not been updated"
args = ["not ", "", "ONE"]

result = testString.replace(...args)
a

Adam Cameron

09/23/2022, 2:13 PM
interesting. Unfortunately in my situation it was for a
queryExecute
call, so no member function available. But it easily work-round-about... it's only three parameters and it was no probs to just refer to them "normally". Still: it should work, right?
s

Scott Steinbeck

09/23/2022, 3:22 PM
i had no idea the spread operator worked in lucee
JK it doesnt
@zackster do you know if the rest/spread operator is being added to lucee 6?
s

seancorfield

09/23/2022, 3:49 PM
It is one of those "doesn't work with BIF" things in ACF?
z

zackster

09/23/2022, 3:55 PM
a

Adam Cameron

09/23/2022, 5:21 PM
Yeah I had forgotten it didn't work in Lucee at all... that was my starting point with this today. Annoying. Flagged for Lucee 6's backlog I think. I don't wanna use it often but it's a bloody shame it doesn't work for me when I do need it 😕
It is one of those "doesn't work with BIF" things in ACF?
It really worries me what's going on under the hood where an operator works in some contexts, but doesn't work in some other largely analogous contexts. It's like it's something the CF Team just band-aids into place where it occurs to them it's needed, rather than doing a proper self-contained & complete implementation.
z

zackster

09/23/2022, 5:27 PM
a

Adam Cameron

09/23/2022, 5:28 PM
No the spread operator, as per the thread
z

zackster

09/23/2022, 5:29 PM
it's coz BIFs are compiled to faster bytecode I'm guessing
a

Adam Cameron

09/23/2022, 5:29 PM
(however I concluded that the reason for the spread operator not working on BIFs in CF could be related to the same reason
argumentCollection
dun't either).
"fails to work as you'd expect even faster!" Not a win.
@zackster I think you mean to be posting in this thread ;-)
but yes, it's a compiler exception, not runtime one on CF (my original gist)
z

zackster

09/23/2022, 5:37 PM
yeah i was demonstrating the parser exception with any operators, that fails on ACF but works for supported operators on Lucee
a

Adam Cameron

09/23/2022, 5:37 PM
trycf is being... obstructive getting details... I'll spin up a local CF2021 instance an see what the error detail is
z

zackster

09/23/2022, 5:38 PM
^^^^ my pet hate with trycf
a

Adam Cameron

09/23/2022, 5:38 PM
I have raised it with @abram so many times I don't bother any more cos he doesn't quite completely hate me for it yet, and I'd like to keep it that way 😉
It's the main thing cflive.net (RIP) had over it, and why I used to prefer it.
Copy code
coldfusion.compiler.validation.OptionalArgMismatchException: Parameter validation error for the REPLACE function.
(for the spread operator example)
Your one fails cos you have the syntax of try/catch wrong 😉
catch (e)
should be (for example)
catch (any e)
. It's supposed to take an exception type. That Lucee doesn't require it is just... a dumb incompat "feature".
But the
-args
thing works OK if you fix that.
(you had me worried for a bit there)