-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
support pick(last) #2716
Comments
Since |
Yes, but redefining last/1 as
So I think the question is: is there a better way to resolve the issue? |
Oops, I misread the last sentence of your comment. Yes, that looks like a reasonable change. |
I think making EDIT: Well, it tries to: jv jv_array_set(jv j, int idx, jv val) {
assert(JVP_HAS_KIND(j, JV_KIND_ARRAY));
if (idx < 0) // <---- here
idx = jvp_array_length(j) + idx;
if (idx < 0) {
jv_free(j);
jv_free(val);
return jv_invalid_with_msg(jv_string("Out of bounds negative array index"));
}
// copy/free of val,j coalesced
jv* slot = jvp_array_write(&j, idx);
jv_free(*slot);
*slot = val;
return j;
} |
|
The problem is that using I think what we might want here is for |
This patch fixes this, but maybe might break something else:
With more context so it's easier to understand:
So we turn negative indices into positive ones in the implementation of Now I think this patch is desirable. I can see more bugs cropping up due to I think it's unlikely that this patch breaks any existing jq code, though it is possible. |
I've incorporated @nicowilliams' change (#2716 (comment)) and reverted to the old Should I scrap #2717 and create a new PR? |
Fixed by #2779 |
Using a version of jq with pick/1:
So the failure of
pick(last)
could be resolved by redefiningdef last: .[length-1];
but is there a better solution? It's not clear to me why pick(.[-1]) should fail.
The text was updated successfully, but these errors were encountered: