Unexpected scope lookup with VARIABLES and ARGUMENTS name conflict

Description

The situation is that I have a function in a script block, and the function has an argument with the same name as a variable in the outer variables scope. In my function code, I reference the argument but, when I call it, I passed in no value.

I think the code should have thrown an error, telling me that the argument I'm obviously referenced hasn't been defined. Lucee instead looked up into the variables scope and found the variable there. I feel like this is unexpected behavior as it's obvious that my code meant to reference the arguments scope.

There is no issue if I pass a value to the function. There is also no issue if I define a default value or require the argument. It's only in this example, which is a logic error, that I see the unexpected behavior.

<:script> msg = 'Hello'; function exclaim( msg ) { var exclamation = msg & '!'; dump( exclamation ); } function exclaim2( msg = '' ) { var exclamation = msg & '!'; dump( exclamation ); } exclaim(); // Should error, but shows 'Hello!' exclaim('Goodbye'); // Shows 'Goodbye!' exclaim2(); // Shows '!' </:script>

I see this same behavior in Lucee running as CFML dialect and Lucee dialect. I did my testing in the Lucee dialect.

Environment

None

Activity

Show:

Michael Offner 5 October 2015 at 14:43

with full null support enabled or the lucee dialect not passing an argument is no linger handled like passing null.
testcase:
https://github.com/lucee/Lucee/commit/07345fbf37627316d7af23a6292faef5a62dbe5b

Michael Offner 14 April 2015 at 15:37

yes this is a bug

Michael Offner 14 April 2015 at 15:37

Miles Rausch 14 April 2015 at 14:04

@michaeloffner Since I was running my code as a `.lucee` file, then this would be a bug, right? Do I need to change any Lucee settings to get the behavior I'm expecting from a `.lucee` file? From the documentation, it looks like it should enforce this sort of thing out of the box.

Michael Offner 14 April 2015 at 07:33

we had already a ticket aout this in the Railo ticket system.

There are 2 aspects on this.

  1. Full null support disabled (only with the CFML dialect)
    CFML has a very odd behaviour with that, in ACF it is even worse, take this example

function test(arg1) { echo("->"&arguments['arg1']); // outputs "->" in Lucee and ACF echo("->"&arguments.arg1); // outputs "->" in Lucee and thows an exception in ACF! echo("->"&arg1); // outputs "->" in Lucee and thows an exception in ACF! }

so depending on the syntax ACF is hangling this different, for us this was a now go, so we decided to handle it always the sam way, independent of the syntax and we have chosen the way that is most compatible to ACF.

2. full null support enabled (always with the Lucee dialect)
Lucee is here definitely off and we need adjustments, if full null support is enabled your example should exactly act like you suggested in your code comment, no question about that!

Fixed

Details

Assignee

Reporter

Priority

Labels

Fix versions

New Issue warning screen

Before you create a new Issue, please post to the mailing list first https://dev.lucee.org

Once the issue has been verified, one of the Lucee team will ask you to file an issue

Affects versions

Created 13 April 2015 at 15:08
Updated 5 October 2015 at 14:45
Resolved 5 October 2015 at 14:45