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

Error in any(generator;condition) #2073

Closed
aio-su opened this issue Mar 3, 2020 · 1 comment · Fixed by #2750
Closed

Error in any(generator;condition) #2073

aio-su opened this issue Mar 3, 2020 · 1 comment · Fixed by #2750
Labels

Comments

@aio-su
Copy link

aio-su commented Mar 3, 2020

Describe the bug
Some conditions lead any(generator;condition) to wrong result.
Use any() for same array input lead to right result
To Reproduce
jq -n '{"a":"1","b":"2","c":"3"}|any(keys[]|tostring?;true)' => false
jq -n '{"a":"1","b":"2","c":"3"}|any(keys[]|tostring;true)' => true
jq -n '{"a":"1","b":"2"}|any(keys[]|tostring?;true)' => true
jq -n '{"a":"1","b":"2","c":"3"}|[keys[]|tostring?|true]|any' => true
Expected behavior
Environment (please complete the following information):
uname -all
=>
Linux LAB-hub1 4.15.0-23-generic #25~16.04.1-Ubuntu SMP Fri May 25 04:50:20 UTC 2018 x86_64 x86_64 x86_64 GNU/Linux

jq --version
=>
jq-1.5-1-a5b5cbe

@itchyny itchyny added the support label Jun 3, 2023
@itchyny
Copy link
Contributor

itchyny commented Jun 25, 2023

I first thought the behavior of has been fixed by #1845 (41b8593), but the examples yield multiple values unexpectedly. But this is the instance of the issue #1859, so closing.

@itchyny itchyny closed this as completed Jun 25, 2023
emanuele6 pushed a commit that referenced this issue Jul 24, 2023
Close #1885, #2140, #2011, #2220, #2485, #2073

Rename the FORK_OPT opcode to TRY_BEGIN, add a TRY_END opcode, and wrap
errors when raising through a TRY_END so that they will not be caught by
the matching TRY_BEGIN.

Now a `try exp catch handler` expression generates code like:

    TRY_BEGIN handler
    <exp>
    TRY_END
    JUMP past_handler
    handler: <handler>
    past_handler:
    ...

On backtrack through TRY_BEGIN it just backtracks.

If anything past the whole thing raises when <exp> produced a value,
then the TRY_END will catch the error, wrap it in another, and
backtrack.  The TRY_BEGIN will see a wrapped error and then it will
unwrap and re-raise the error.

If <exp> raises, then TRY_BEGIN will catch the error and jump to the
handler, but the TRY_BEGIN will not stack_save() in that case, so on
raise/backtrack the TRY_BEGIN will not execute again (nor will the
TRY_END).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants