diff --git a/src/compile.c b/src/compile.c index 44479e37..849e2f1d 100644 --- a/src/compile.c +++ b/src/compile.c @@ -893,7 +893,7 @@ block gen_destructure(block var, block matcher, block body) { if (body.first && body.first->op == TOP) top = inst_block(block_take(&body)); - return BLOCK(top, gen_op_simple(DUP), var, bind_matcher(matcher, body)); + return BLOCK(top, gen_op_simple(DUP), gen_subexp(var), gen_op_simple(POP), bind_matcher(matcher, body)); } // Like gen_var_binding(), but bind `break`'s wildcard unbound variable diff --git a/tests/jq.test b/tests/jq.test index f510a917..47b842c4 100644 --- a/tests/jq.test +++ b/tests/jq.test @@ -1356,3 +1356,9 @@ IN(range(5;20); range(10)) null true +# Regression test for #1347 +(.a as $x | .b) = "b" +{"a":null,"b":null} +{"a":null,"b":"b"} + +