From c8a2a0acc23e87cb28db794ee95f7d8b87d3ccbb Mon Sep 17 00:00:00 2001 From: William Langford Date: Fri, 17 Feb 2017 00:40:26 -0500 Subject: Fix a tripped assertion when generating reduces A noop body, while useless, should still compile successfully --- src/compile.c | 7 ++++++- tests/jq.test | 5 +++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/src/compile.c b/src/compile.c index 63229438..7960cfe6 100644 --- a/src/compile.c +++ b/src/compile.c @@ -824,7 +824,12 @@ static block bind_alternation_matchers(block matchers, block body) { block gen_reduce(block source, block matcher, block init, block body) { block res_var = gen_op_var_fresh(STOREV, "reduce"); block update_var = gen_op_bound(STOREV, res_var); - block jmp = gen_op_target(JUMP, body); + block jmp = gen_op_targetlater(JUMP); + if (body.last == NULL) { + inst_set_target(jmp, jmp); + } else { + inst_set_target(jmp, body); + } block loop = BLOCK(gen_op_simple(DUPN), source, bind_alternation_matchers(matcher, diff --git a/tests/jq.test b/tests/jq.test index ac784ef8..2882d9c4 100644 --- a/tests/jq.test +++ b/tests/jq.test @@ -710,6 +710,11 @@ reduce range(5) as $n ([]; select($n%2 == 1) | . + [$n]) null [1,3] +# This, while useless, should still compile. +reduce . as $n (.; .) +null +null + . as $dot|any($dot[];not) [1,2,3,4,true,false,1,2,3,4,5] true -- cgit v1.2.3