-
-
Notifications
You must be signed in to change notification settings - Fork 607
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
Unexpected order when adding multiple elements to array #2143
Comments
It looks like operators have right associativity, i.e. Normally I'm not sure if making all the operators right-associative was intentional; I suspect it is a side-effect of transforming expressions into a postfix representation internally. This is even more surprising for operators like subtraction that are normally left-associative: $ yq -n '6 - 5 - 4'
5 Here the expression is processed as I don't see how this could be fixed without breaking backwards compatibility, but it would help a lot if this was documented (see #1648). |
Thank you @jandubois ! Verifying with subtraction indeed make it more obvious:
|
@ryenus Just in case it wasn't obvious, you can avoid these issues by always adding parenthesis explicitly: $ yq -n '([] + {"a":1}) + {"b":2}'
- a: 1
- b: 2 |
Agreed, for array concatenation, another workaround is to wrap the 2nd operand also in an array:
|
Describe the bug
When trying to sequentially append two objects to an array, say
array + o1 + o2
, instead of appending o1 then appending o2, yq combined the objects o1 and o2, then appended the new object to the array.Version of yq: 4.44.3
Operating system: mac
Installed via: homebrew
Input Yaml
N/A
Command
The command you ran:
yq -n '[] + {"a":1} + {"b":2}'
Actual behavior
Expected behavior
Additional context
Add any other context about the problem here.
The text was updated successfully, but these errors were encountered: