From a81edc2c7f1a8110ccc77ef9c73a462af33565dd Mon Sep 17 00:00:00 2001 From: Kaz Kylheku Date: Wed, 2 Aug 2023 18:25:14 -0700 Subject: bug: :vars not usable with :counter in @(repeat). This is a regression due to a March 2016 commit which introduced the ability for :vars in an output-side @(repeat) block to have initial values. The bug has the effect that all arguments in @(repeat) which are conses/lists get duplicated, which messes up the property list structure. * parser.y (expand_repeat_rep_args): Do not unconditionally add reg to the output at the bottom of the loop. A few cases above in the consp(arg) case handle that themselves, and do not continue the loop, so control ends up at the bottom, adding a spurious item. By removing this list_collect, we have to introduce it to just one case which relies on it. * tests/008/repeat.txr, * tests/008/repeat.expected: New files. * y.tab.c.shipped: Updated. --- parser.y | 2 +- tests/008/repeat.expected | 3 +++ tests/008/repeat.txr | 6 ++++++ y.tab.c.shipped | 2 +- 4 files changed, 11 insertions(+), 2 deletions(-) create mode 100644 tests/008/repeat.expected create mode 100644 tests/008/repeat.txr diff --git a/parser.y b/parser.y index 91643693..2a42923c 100644 --- a/parser.y +++ b/parser.y @@ -1634,10 +1634,10 @@ static val expand_repeat_rep_args(val args) } } else if (exp_pair) { match_reg_var(arg); + ptail = list_collect(ptail, arg); } exp_pair = exp_pairs = nil; - ptail = list_collect(ptail, arg); } return out; diff --git a/tests/008/repeat.expected b/tests/008/repeat.expected new file mode 100644 index 00000000..495d096a --- /dev/null +++ b/tests/008/repeat.expected @@ -0,0 +1,3 @@ +1 3 a +2 3 b +3 3 c diff --git a/tests/008/repeat.txr b/tests/008/repeat.txr new file mode 100644 index 00000000..dba54831 --- /dev/null +++ b/tests/008/repeat.txr @@ -0,0 +1,6 @@ +@(bind a ("a" "b" "c")) +@(output) +@(repeat :counter (i 1) :vars ((x (len a)))) +@i @x @a +@(end) +@(end) diff --git a/y.tab.c.shipped b/y.tab.c.shipped index 31da32e7..f1377d67 100644 --- a/y.tab.c.shipped +++ b/y.tab.c.shipped @@ -7351,10 +7351,10 @@ static val expand_repeat_rep_args(val args) } } else if (exp_pair) { match_reg_var(arg); + ptail = list_collect(ptail, arg); } exp_pair = exp_pairs = nil; - ptail = list_collect(ptail, arg); } return out; -- cgit v1.2.3