Skip to content

Commit

Permalink
Conditional exprs are not path exprs (fix jqlang#1368)
Browse files Browse the repository at this point in the history
The conditional expression in if-then-elif-else-end cannot contribute to
path expressions because it doesn't change the input to any of the then/
elif/else expressions.  These must be generated via gen_subexp().

See also jqlang#1366.
  • Loading branch information
nicowilliams committed Mar 15, 2017
1 parent 674e9fb commit b142d48
Show file tree
Hide file tree
Showing 2 changed files with 6 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 @@ -905,7 +905,7 @@ static block gen_wildvar_binding(block var, const char* name, block body) {
}

block gen_cond(block cond, block iftrue, block iffalse) {
return BLOCK(gen_op_simple(DUP), cond,
return BLOCK(gen_op_simple(DUP), BLOCK(gen_subexp(cond), gen_op_simple(POP)),
gen_condbranch(BLOCK(gen_op_simple(POP), iftrue),
BLOCK(gen_op_simple(POP), iffalse)));
}
Expand Down
5 changes: 5 additions & 0 deletions tests/jq.test
Original file line number Diff line number Diff line change
Expand Up @@ -1382,4 +1382,9 @@ true
{"a":null,"b":null}
{"a":null,"b":"b"}

# Regression test for #1368
(.. | select(type == "object" and has("b") and (.b | type) == "array")|.b) |= .[0]
{"a": {"b": [1, {"b": 3}]}}
{"a": {"b": 1}}


0 comments on commit b142d48

Please sign in to comment.