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

          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.
          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.
          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
          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
          Nathan Bubna added a comment -

          Fixed in revision 705288.

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

            People

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

              Dates

              • Created:
                Updated:
                Resolved:

                Development