Velocity
  1. Velocity
  2. VELOCITY-630

Pass by name does not work with #foreach within a macro

    Details

    • Type: Bug Bug
    • Status: Resolved
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: 1.5, 1.6-beta1
    • Fix Version/s: 1.6
    • Component/s: Engine
    • Labels:
      None

      Description

      GIven the following:

      #macro(test $a $b)
      #foreach($i in $a) $b #end
      #end
      #test( [1, 2, 3] "#if($i == 2) yes #else no #end")

      I would expect the output:

      no yes no

      Instead, I get

      no no no

      The Foreach directive explicitly sets $i in the localscope. This change was made for VELOCITY-285 . Before 285 Velocity correctly gave the results "no yes no" which is svn revision number 471881.

        Issue Links

          Activity

          Transition Time In Source Status Execution Times Last Executer Last Execution Date
          Open Open Resolved Resolved
          3d 17h 1 Nathan Bubna 16/Oct/08 18:13
          Mark Thomas made changes -
          Workflow Default workflow, editable Closed status [ 12551584 ] jira [ 12552469 ]
          Mark Thomas made changes -
          Workflow jira [ 12443977 ] Default workflow, editable Closed status [ 12551584 ]
          Nathan Bubna made changes -
          Fix Version/s 1.6 [ 12310290 ]
          Status Open [ 1 ] Resolved [ 5 ]
          Resolution Fixed [ 1 ]
          Hide
          Nathan Bubna added a comment -

          Fixed in revision 705288.

          Show
          Nathan Bubna added a comment - Fixed in revision 705288.
          Hide
          Nathan Bubna added a comment -

          In this the "Strange pass by name behavior" thread on the dev list, Byron points out that the changes made for VELOCITY-285 don't fit with strict pass-by-name behavior. I'm convinced at this point. In the absence of any argument against that. I'm going to revert the relevant change in VELOCITY-285 in favor of resolving this issue. Here's the thread for anyone interested:

          http://velocity.markmail.org/search/?q=strange%20pass%20by%20name#query:strange%20pass%20by%20name+page:2+mid:lb4czzlcndwizoz3+state:results

          Show
          Nathan Bubna added a comment - In this the "Strange pass by name behavior" thread on the dev list, Byron points out that the changes made for VELOCITY-285 don't fit with strict pass-by-name behavior. I'm convinced at this point. In the absence of any argument against that. I'm going to revert the relevant change in VELOCITY-285 in favor of resolving this issue. Here's the thread for anyone interested: http://velocity.markmail.org/search/?q=strange%20pass%20by%20name#query:strange%20pass%20by%20name+page:2+mid:lb4czzlcndwizoz3+state:results
          Hide
          Byron Foster added a comment -

          This bug was introduced with this issue

          Show
          Byron Foster added a comment - This bug was introduced with this issue
          Byron Foster made changes -
          Link This issue blocks VELOCITY-285 [ VELOCITY-285 ]
          Hide
          Byron Foster added a comment -

          Yes, my feeling is that this is non-trivial, and is certainly a step softly kind of fix.

          Show
          Byron Foster added a comment - Yes, my feeling is that this is non-trivial, and is certainly a step softly kind of fix.
          Nathan Bubna made changes -
          Field Original Value New Value
          Attachment Velocity630TestCase.java [ 12392033 ]
          Hide
          Nathan Bubna added a comment -

          Don't have much time to go after this today. Here's a test case for both VELOCITY-285 and this one. Guess we need to find a way to get both to pass.

          Show
          Nathan Bubna added a comment - Don't have much time to go after this today. Here's a test case for both VELOCITY-285 and this one. Guess we need to find a way to get both to pass.
          Byron Foster created issue -

            People

            • Assignee:
              Unassigned
              Reporter:
              Byron Foster
            • Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:

                Development