Uploaded image for project: 'Lucee Development'
  1. LDEV-273

Unexpected scope lookup with VARIABLES and ARGUMENTS name conflict

    Details

    • Type: Bug
    • Status: Deployed
    • Priority: New
    • Resolution: Fixed
    • Affects Version/s: 5.0.0.43
    • Fix Version/s: 5.0.0.81
    • Labels:

      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.

      Unable to find source-code formatter for language: cfml. Available languages are: actionscript, ada, applescript, bash, c, c#, c++, cpp, css, erlang, go, groovy, haskell, html, java, javascript, js, json, lua, none, nyan, objc, perl, php, python, r, rainbow, ruby, scala, sh, sql, swift, visualbasic, xml, yaml
      <: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.

        Attachments

          Activity

            People

            • Assignee:
              michaeloffner Michael Offner
              Reporter:
              awayken Miles Rausch
            • Votes:
              1 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: