From c2bfe5ccf81e5d035354d002a962b2db5525bd6d Mon Sep 17 00:00:00 2001 From: Ben Pfaff Date: Thu, 21 Mar 2024 06:32:56 -0700 Subject: [PATCH] DO REPEAT: Accept duplicate names as substitution variables. Thanks to Frans Houweling for reporting the bug. --- src/language/commands/repeat.c | 3 ++- src/language/lexer/variable-parser.c | 2 +- tests/language/commands/do-repeat.at | 25 +++++++++++++++++++++++++ 3 files changed, 28 insertions(+), 2 deletions(-) diff --git a/src/language/commands/repeat.c b/src/language/commands/repeat.c index af0d89d59..665b97aa7 100644 --- a/src/language/commands/repeat.c +++ b/src/language/commands/repeat.c @@ -326,7 +326,8 @@ static bool parse_ids (struct lexer *lexer, const struct dictionary *dict, struct dummy_var *dv) { - return parse_mixed_vars (lexer, dict, &dv->values, &dv->n_values, PV_NONE); + return parse_mixed_vars (lexer, dict, &dv->values, &dv->n_values, + PV_DUPLICATE); } /* Adds REPLACEMENT to MACRO's list of replacements, which has diff --git a/src/language/lexer/variable-parser.c b/src/language/lexer/variable-parser.c index 3b3b46e67..2977c2fb7 100644 --- a/src/language/lexer/variable-parser.c +++ b/src/language/lexer/variable-parser.c @@ -525,7 +525,7 @@ parse_DATA_LIST_vars (struct lexer *lexer, const struct dictionary *dict, bool ok = false; - assert ((pv_opts & ~(PV_APPEND | PV_SINGLE + assert ((pv_opts & ~(PV_APPEND | PV_SINGLE | PV_DUPLICATE | PV_NO_SCRATCH | PV_NO_DUPLICATE)) == 0); stringi_set_init (&set); diff --git a/tests/language/commands/do-repeat.at b/tests/language/commands/do-repeat.at index 81bc952bc..32c9a0531 100644 --- a/tests/language/commands/do-repeat.at +++ b/tests/language/commands/do-repeat.at @@ -251,4 +251,29 @@ do-repeat.sps:16: error: DO REPEAT: Each dummy variable must have the same numbe error: DO REPEAT: At end of input: Syntax error expecting END REPEAT. ]) +AT_CLEANUP + +AT_SETUP([DO REPEAT -- duplicate substitutions]) +AT_DATA([do-repeat.sps], [dnl +DATA LIST LIST NOTABLE / numer1 numer2 denom1. +BEGIN DATA +30 25 100 +20 15 100 +10 40 100 +20 10 100 +END DATA. + +* Check that duplicates are OK for both existing (denom1) + and nonexistent (perc1) variables. +DO REPEAT n=numer1 numer2 + /d = denom1 denom1 + /p = perc1 perc1. + COMPUTE p = n / d * 100. +END REPEAT PRINT. +]) +AT_CHECK([pspp do-repeat.sps], [0], [dnl + COMPUTE perc1 = numer1 / denom1 * 100. + + COMPUTE perc1 = numer2 / denom1 * 100. +]) AT_CLEANUP \ No newline at end of file -- 2.11.4.GIT