Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

PATCH: the ::= fix in 54674 mistreated positional arguments



% foo=xxx; () { echo ${2::=$foo} } yyy
yyy

We get the argv parameter returned when asking for "2" so use getvalue()
to get a vbuf with the proper start/end set instead of making up bogus
values.

---

dana noticed this problem on irc.

The final typeset -u arr test was to check if the bracks argument should be 0 or 1,
and it should definitely be 0.

 Src/subst.c            | 13 +++++++------
 Test/D04parameter.ztst | 23 +++++++++++++++++++++++
 2 files changed, 30 insertions(+), 6 deletions(-)

diff --git a/Src/subst.c b/Src/subst.c
index f7e7a835ef..c2cda8419e 100644
--- a/Src/subst.c
+++ b/Src/subst.c
@@ -3318,13 +3318,14 @@ paramsubst(LinkList l, LinkNode n, char **str, int qt, int pf_flags,
 		    arrasg = 0;
 		} else {
 		    untokenize(val);
-		    Param pm = setsparam(idbeg, ztrdup(val));
-		    if (pm) {
+		    if (setsparam(idbeg, ztrdup(val))) {
 			struct value vbuf = { 0 };
-			vbuf.pm = pm;
-			vbuf.end = -1;
-			vbuf.valflags = VALFLAG_SUBST;
-			val = getstrvalue(&vbuf);
+			char *p = idbeg;
+			Value v = getvalue(&vbuf, &p, 0);
+			if (v) {
+			    v->valflags = VALFLAG_SUBST;
+			    val = ztrdup(getstrvalue(v));
+			}
 		    }
 		}
 		*idend = sav;
diff --git a/Test/D04parameter.ztst b/Test/D04parameter.ztst
index 97577fd4ee..0415751ac9 100644
--- a/Test/D04parameter.ztst
+++ b/Test/D04parameter.ztst
@@ -95,6 +95,29 @@
 >5.00e+00
 >1 2 3
 
+  foo=xxx
+  () { echo ${2::=$foo} ${3::=$foo} ${4::=$foo}; echo $2 } yyy
+  () { echo ${11::=$foo}; echo $11 } yyy blah
+0:::= doesn't do weird things with positional arguments
+>xxx xxx xxx
+>xxx
+>xxx
+>xxx
+
+  five=5 arr=( a b )
+  () { print -rl - ${arr[2]::=$five} }
+  () { print -rl - ${1::=$2} } x y
+  () { print -rl - ${1::=$five} ${2::=$five} ${9::=$five} } x y
+  typeset -u arr
+  () { print -rl - ${arr[2]::=Five} }
+0:regression: ::= with multiple assignments
+>5
+>y
+>5
+>5
+>5
+>Five
+
   unset array
   print ${#${(A)=array=word}}
 0:${#${(A)=array=word}} counts array elements
-- 
2.38.1





Messages sorted by: Reverse Date, Date, Thread, Author