summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog4
-rw-r--r--Src/loop.c2
-rw-r--r--Test/A05execution.ztst14
3 files changed, 19 insertions, 1 deletions
diff --git a/ChangeLog b/ChangeLog
index 9df308c54..54cc37f67 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,9 @@
2020-08-08 Daniel Shahaf <d.s@daniel.shahaf.name>
+ * 47296 (+ unposted additional tests and comments): Src/loop.c,
+ Test/A05execution.ztst: 'repeat' loops: Let the repeat count
+ use $?.
+
* 47300: Src/parse.c, Src/zsh.h: Document the EC_NODUP, EC_DUP,
EC_DUPTOK triplet.
diff --git a/Src/loop.c b/Src/loop.c
index f13c8c4a9..41b2e5627 100644
--- a/Src/loop.c
+++ b/Src/loop.c
@@ -497,7 +497,6 @@ execrepeat(Estate state, UNUSED(int do_exec))
end = state->pc + WC_REPEAT_SKIP(code);
- lastval = 0;
tmp = ecgetstr(state, EC_DUPTOK, &htok);
if (htok) {
singsub(&tmp);
@@ -506,6 +505,7 @@ execrepeat(Estate state, UNUSED(int do_exec))
count = mathevali(tmp);
if (errflag)
return 1;
+ lastval = 0; /* used when the repeat count is zero */
pushheap();
cmdpush(CS_REPEAT);
loops++;
diff --git a/Test/A05execution.ztst b/Test/A05execution.ztst
index 20a594b68..c65642988 100644
--- a/Test/A05execution.ztst
+++ b/Test/A05execution.ztst
@@ -401,3 +401,17 @@ F:anonymous function, and a descriptor leak when backgrounding a pipeline
(( exit 130 ) | { sleep 1; echo hello })
0:exit code 130 isn't mistaken for a signal (unit test for workers/46060)
>hello
+
+ (exit 3); repeat "$?" echo x
+ (exit 3); repeat '?' echo y
+0:'repeat' loop can use lastval in the count
+>x
+>x
+>x
+>y
+>y
+>y
+
+ (exit 4); repeat 0 do done
+0:'repeat 0' resets lastval
+