jq icon indicating copy to clipboard operation
jq copied to clipboard

Fix assertion when using multiple data imports

Open wtlangford opened this issue 5 years ago • 3 comments

import "a" as $a;
import "b" as $b;
def f: $a,$b;
f

This fails an assertion: Assertion failed: (var < fr->bc->nlocals), function frame_local_var, file src/execute.c, line 104.

The issue appears to be that we don't properly increment the number of local vars defined in the frame where we STORE_GLOBAL, which means we can easily have more vars stored than we expect in our assertions. The code for STOREV does increment this, so I duplicated that logic into STORE_GLOBAL. I can't think of any ways that this might cause issues. @nicowilliams can you?

wtlangford avatar Oct 26 '19 22:10 wtlangford

Coverage Status

Coverage decreased (-0.01%) to 84.542% when pulling 058ebda4b77363ec4f78ef561de9db4b4be7b827 on wtlangford:fix-store-global into bda75c3142d969e2a52301a1eaead0cc05ec2c13 on stedolan:master.

coveralls avatar Oct 26 '19 22:10 coveralls

I just ran into the same issue. It'd be really awesome if this were merged so I didn't have to resort to the hack of concatenating all my data files so I can import them all at once and access them as array members. Alternatively, if importing JSON data is supposed to be restricted to one file, that should be documented.

irgeek avatar Dec 22 '20 03:12 irgeek

I also ran into this just now, assume {a,b}.json exist and are valid JSON, then consider the following snippet:

import "./a" as $a;
import "./b" as $b;

def a: $a;
def b: $b;

When completed with either

{a: a}

or

{b: b}

it will evaluate. However, when completed with

{a: a} * {b: b}

it fails with

jq: src/execute.c:104: frame_local_var: Assertion `var < fr->bc->nlocals' failed.

That's quite confusing, and I spent quite a lot of time figuring out what's going on. Please fix this!

lorenzleutgeb avatar Feb 21 '22 10:02 lorenzleutgeb

LGTM, I will merge this patch with the following test, thank you.

jq -n -c -L tests/modules 'import "data" as $a; import "data" as $b; def f: {$a, $b}; f'

itchyny avatar Jul 20 '23 23:07 itchyny