Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

? operator eagerly suppresses break errors #1858

Closed
nicowilliams opened this issue Mar 7, 2019 · 2 comments
Closed

? operator eagerly suppresses break errors #1858

nicowilliams opened this issue Mar 7, 2019 · 2 comments

Comments

@nicowilliams
Copy link
Contributor

These two should have the same output:

$ jq -n 'label $out | ((1, break $out, 2), "here", halt)'
1
$ 
$ jq -n 'label $out | ((1, break $out, 2)?, "here", halt)'
1
"here"

Whereas try gets it better, but still not entirely right:

$ jq -n 'label $out | ((try (1, break $out, 2) catch error), "here", halt)'
1
$ 
$ jq -cn 'label $out | ((try (1, break $out, 2) catch .), "here", halt)'
1
{"__jq":0}
"here"
$ 
@nicowilliams
Copy link
Contributor Author

See also #1859.

@nicowilliams
Copy link
Contributor Author

Actually, this is a dup of #1859.

Consider a simpler example:

$ jq -n '{a:1}|.a?|error'
jq: error (at <unknown>) (not a string): 1
$ jq -n '{a:1}|(.a)?|error'
$

In the first example the ? modifies the index operation and the compiler uses INDEX_OPT, which only suppresses generation of errors from the index operation.

In the second example the compiler fails to see the optimization opportunity and uses FORK_OPT instead, which has all the problems described in #1859.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant