You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@velocity.apache.org by "Will Glass-Husain (JIRA)" <ji...@apache.org> on 2005/09/19 00:54:54 UTC
[jira] Updated: (VELOCITY-285) reference within macro and foreach is incorrect
[ http://issues.apache.org/jira/browse/VELOCITY-285?page=all ]
Will Glass-Husain updated VELOCITY-285:
---------------------------------------
Bugzilla Id: (was: 30343)
Summary: reference within macro and foreach is incorrect (was: recursion and loop)
Fix Version: 1.5
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.
was:
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.
Environment:
Operating System: other
Platform: Other
was:
Operating System: other
Platform: Other
Assign To: (was: Velocity-Dev List)
Priority: Minor (was: Major)
Very interesting. The problem appears to be that outside of the #foreach, $p refers to the local $p. Inside of #foreach, $p refers to a global $p.
This example is a little more instructive:
#macro (test_loop $p)
call to test_loop ($p)
#foreach($child in $p)
in the loop the param should not be changed : ($p) / ($child)
#test_loop($child)
#end
return
#end
#set($l1=["a"])
#set($l = [$l1])
#test_loop($l)
producing:
call to test_loop ([[a]])
in the loop the param should not be changed : ([[a]]) / ([a])
call to test_loop ([a])
in the loop the param should not be changed : (a) / (a)
call to test_loop (a)
return
return
return
> reference within macro and foreach is incorrect
> -----------------------------------------------
>
> Key: VELOCITY-285
> URL: http://issues.apache.org/jira/browse/VELOCITY-285
> Project: Velocity
> Type: Bug
> Components: Source
> Versions: 1.4
> Environment: Operating System: other
> Platform: Other
> Reporter: Gilles Scokart
> Priority: Minor
> Fix For: 1.5
>
> 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.
--
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
http://issues.apache.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see:
http://www.atlassian.com/software/jira
---------------------------------------------------------------------
To unsubscribe, e-mail: velocity-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: velocity-dev-help@jakarta.apache.org