Skip to content

Commit

Permalink
Allow var bindings in path expressions (#1347)
Browse files Browse the repository at this point in the history
The expression in a variable binding is not and must not be seen as
being part of a path expression in which the variable binding appears.
  • Loading branch information
nicowilliams committed Feb 22, 2017
1 parent 02bad4b commit 8cde328
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/compile.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 6 additions & 0 deletions tests/jq.test
Original file line number Diff line number Diff line change
Expand Up @@ -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"}


0 comments on commit 8cde328

Please sign in to comment.