Velocity
  1. Velocity
  2. VELOCITY-285

reference within macro and foreach is incorrect

    Details

    • Type: Bug Bug
    • Status: Closed
    • Priority: Minor Minor
    • Resolution: Fixed
    • Affects Version/s: 1.4
    • Fix Version/s: 1.5
    • Component/s: Engine
    • Labels:
      None
    • Environment:
      Operating System: other
      Platform: Other

      Description

      It seems that there is a bug when we have loop into a recursive macro.

      Here is the test I run :

      #macro (test_loop $p)
      call to test_loop ($p)
      #foreach($child in $p)
      in the loop the param should not be changed : ($p)
      #test_loop($child)
      #end
      return
      #end

      #set($l1=["a"])
      #set($l = [$l1])
      #test_loop($l)

      It produce:

      call to test_loop ([[a]])
      in the loop the param should not be changed : ([[a]])
      call to test_loop ([a])
      in the loop the param should not be changed : (a)
      call to test_loop (a)
      return
      return
      return

      IMHO, it should be
      call to test_loop ([[a]])
      in the loop the param should not be changed : ([[a]])
      call to test_loop ([a])
      in the loop the param should not be changed : ([a])
      call to test_loop (a)
      return
      return
      return

      The difference is in the second recusive call. I don't know why, but it seems
      that the instruction #foreach($child in $p) has modified $p that contains the
      value of $child.

        Issue Links

          Activity

          Mark Thomas made changes -
          Workflow Default workflow, editable Closed status [ 12551805 ] jira [ 12552295 ]
          Mark Thomas made changes -
          Workflow jira [ 12325160 ] Default workflow, editable Closed status [ 12551805 ]
          Byron Foster made changes -
          Link This issue is blocked by VELOCITY-630 [ VELOCITY-630 ]
          Will Glass-Husain made changes -
          Link This issue relates to VELOCITY-532 [ VELOCITY-532 ]
          Henning Schmiedehausen made changes -
          Status Resolved [ 5 ] Closed [ 6 ]
          Henning Schmiedehausen made changes -
          Resolution Fixed [ 1 ]
          Status In Progress [ 3 ] Resolved [ 5 ]
          Henning Schmiedehausen made changes -
          Status Open [ 1 ] In Progress [ 3 ]
          Henning Schmiedehausen made changes -
          Assignee Henning Schmiedehausen [ henning ]
          Henning Schmiedehausen made changes -
          Bugzilla Id 30343
          Component/s Engine [ 12311337 ]
          Component/s Source [ 12310214 ]
          Will Glass-Husain made changes -
          Summary recursion and loop reference within macro and foreach is incorrect
          Bugzilla Id 30343
          Assignee Velocity-Dev List [ velocity-dev@jakarta.apache.org ]
          Fix Version/s 1.5 [ 12310253 ]
          Priority Major [ 3 ] Minor [ 4 ]
          Environment Operating System: other
          Platform: Other
          Operating System: other
          Platform: Other
          Description It seems that there is a bug when we have loop into a recursive macro.

          Here is the test I run :

          #macro (test_loop $p)
          call to test_loop ($p)
          #foreach($child in $p)
              in the loop the param should not be changed : ($p)
          #test_loop($child)
          #end
          return
          #end

          #set($l1=["a"])
          #set($l = [$l1])
          #test_loop($l)


          It produce:

          call to test_loop ([[a]])
          in the loop the param should not be changed : ([[a]])
          call to test_loop ([a])
          in the loop the param should not be changed : (a)
          call to test_loop (a)
          return
          return
          return

          IMHO, it should be
          call to test_loop ([[a]])
          in the loop the param should not be changed : ([[a]])
          call to test_loop ([a])
          in the loop the param should not be changed : ([a])
          call to test_loop (a)
          return
          return
          return

          The difference is in the second recusive call. I don't know why, but it seems
          that the instruction #foreach($child in $p) has modified $p that contains the
          value of $child.
          It seems that there is a bug when we have loop into a recursive macro.

          Here is the test I run :

          #macro (test_loop $p)
          call to test_loop ($p)
          #foreach($child in $p)
              in the loop the param should not be changed : ($p)
          #test_loop($child)
          #end
          return
          #end

          #set($l1=["a"])
          #set($l = [$l1])
          #test_loop($l)


          It produce:

          call to test_loop ([[a]])
          in the loop the param should not be changed : ([[a]])
          call to test_loop ([a])
          in the loop the param should not be changed : (a)
          call to test_loop (a)
          return
          return
          return

          IMHO, it should be
          call to test_loop ([[a]])
          in the loop the param should not be changed : ([[a]])
          call to test_loop ([a])
          in the loop the param should not be changed : ([a])
          call to test_loop (a)
          return
          return
          return

          The difference is in the second recusive call. I don't know why, but it seems
          that the instruction #foreach($child in $p) has modified $p that contains the
          value of $child.
          Jeff Turner made changes -
          Field Original Value New Value
          issue.field.bugzillaimportkey 30343 12315155
          Gilles Scokart created issue -

            People

            • Assignee:
              Henning Schmiedehausen
              Reporter:
              Gilles Scokart
            • Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:

                Development