I don't even know how to file a bug for this.... ...
# adobe
t
I don't even know how to file a bug for this.... "you can only use 'default' as an argument name on the first argument"? https://trycf.com/gist/36c11f21cad3b38191aeae4da99d3cfa/acf2021?theme=monokai
works fine in lucee, but breaks in all versions of acf.
s
It's not a bug, it's a feature
but I would suspect that if there is a bug, it's that the first argument is allowed to be named default.
it looks like in test2, it is naming the second argument string instead of default
try it this way: <cfscript> WriteDump(test()); WriteDump(test2("test")); function test(string default="blah") { return arguments; } function test2(required string arg, default="blah") { return arguments; } </cfscript>
or this way: <cfscript> WriteDump(test()); WriteDump(test2("test")); function test(string default="blah") { return arguments; } function test2(required string arg, string mystring default="blah") { return arguments; } </cfscript>
when you just put string, for some reason it doesn't see that as a datatype, but the name of the string... very weird that it behaves differently for the second argument than the first
but it is likely because you are using reserved words... don't name your arguments string or default and it will work fine
I think though that it could also be because you have the required on the second function and that is why it is behaving differently
try it this way: <cfscript> WriteDump(test()); WriteDump(test2("test")); function test(string default="blah") { return arguments; } function test2(string default="blah1", string default="blah") { return arguments; } </cfscript> in this case I think that it sees the first argument is named default, then it assumes the second argument is named string because there is already an argument named default
function test2(string="blah1", default="blah") { return arguments; }
that works fine
seems to only be when you add things like data types and set default values if the variable isn't supplied... sorry... I really got into this for some reason
t
it's fine. essentially it ends up boiling down to "coldfusion supports too many syntaxes and parsing is ambiguous as a result"
a
It's not a reserved word thing, otherwise it would not be possible to have an parameter called
default
at all. Also if
function f(string default="default value")
works fine then so should
function f(firstParameter, string default="default value")
This is just CF being shit at parsing CFML. Again.
t
it'd be nice if the error thrown were something along the line of "default is a reserved word" instead of just "default is undefined in arguments"
s
yeah, it is inconsistent between the first and second parameter for sure
Probably CF is being too forgiving of using what really should be reserved words
which leads to unexpected/unpredictable results
a
It might be better to see what it's doing if you just dump out the function itself, not test via calls to the function.

https://i2.paste.pics/f30a8ff5ca48674e8ddc51baf910b5cf.png

It would seem CF has some heretofore unknown syntax that permits one to specify a parameter default with
default="default value"
. Which is news to me.
Is it getting confused with
<cffunction>
??
s
just seems like there is a different order of operations in the baground for parsing parameters after the first parameter
a
OK, I think we're agreed that @Mark Takata (Adobe) needs to go back on the naughty step until it's fixed?
s
in my mind, something like this should throw an error for dupicate argument names:
<cfscript>
WriteDump(f);
function f(string default="blah1", string default="blah2") {
return arguments;
}
</cfscript>
but ACF just names the first one default and the second one string
my guess is that after the first argument, there is some check to see if there is another argument with the same name, and if there is, it then tries to see if there is another way to look at the second argument and in this case calls it string.
if there is only one argument, there is no need to do the duplicate name check so it behaves differently
t
On a hunch, this works:
Copy code
function test2(required string blah, default type="string" default="blah") {
    return arguments.default;
}
The syntax that was unknown to @Adam Cameron is I think generically pervasive, and i was familiar with because docbox makes extensive use of it. You can do argument name, followed by name value pairs, cfargument style.
s
oh my
a
ah, yeah.
m
For the last time Adam, I'm not on stuck on the naughty step. The naughty step is stuck on ME.
a
HAHAHAHAHAHA, OK Rorschach
s
is that something you made just now... or have you been anxiously awaiting an opportunity to use that meme?
(not that you would have had to wait very long)
a
It's just his business card, innit?
m
no cards here mate. i use dot. 😉
a
Come on pal. I'm sure you could get a personalised one.
m
why do you hate trees adam
a
Can't trust 'em. They're always watching me. Waiting.
m
Fair.