fix: reduce/foreach state variable should not be reset each iteration (#3205)

When the UPDATE query in a reduce or foreach syntax does not emit
a value, it should simply skip updating the state variable. But
currently it resets the state variable to null.
This commit is contained in:
itchyny authored and GitHub committed 2024-11-21 08:12:18 +09:00
1 parent 8619f8a8ac
commit 96e8d893c1
2 files changed
+10 -2

No files matched your search

+2 -2
View File
@@ -832,7 +832,7 @@ block gen_reduce(block source, block matcher, block init, block body) {
block loop = BLOCK(gen_op_simple(DUPN),
source,
bind_alternation_matchers(matcher,
BLOCK(gen_op_bound(LOADVN, res_var),
BLOCK(gen_op_bound(LOADV, res_var),
body,
gen_op_bound(STOREV, res_var))),
gen_op_simple(BACKTRACK));
@@ -854,7 +854,7 @@ block gen_foreach(block source, block matcher, block init, block update, block e
// in the body to see
bind_alternation_matchers(matcher,
// load the loop state variable
BLOCK(gen_op_bound(LOADVN, state_var),
BLOCK(gen_op_bound(LOADV, state_var),
// generate updated state
update,
// save the updated state for value extraction