-
Notifications
You must be signed in to change notification settings - Fork 440
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
std.mergePatch doesn't respect laziness #216
Comments
When you use a in The mergePatch just adds It sounds like what you wanted was this:
Or even just
BTW This is not about laziness but about late binding. The difference is: Lazy evaluation chooses to evaluate the expression bound to a variable at the first time the variable is used, as opposed to when the binding was made (which is almost always much earlier). The practical difference is that with laziness the expression will not be evaluated unless it is actually needed, which becomes important when you have error statements / asserts etc that could fire in that expression (see also non-termination although that does not occur in practice in Jsonnet). Late binding chooses the expression to be evaluated depending on the concrete class of the target object. I.e., you don't know what the expression even is going to be until execution time when the concrete class is known. Jsonnet doesn't have classes but the concept is the same for prototype inheritance. |
Closing for inactivity, please re-open if you like |
Thanks for the detailed explanation! |
Sorry to bring up such an old issue, but I'm hitting this too and I think I have a clearer example:
The output is This produces the same result (the output has b = 1):
where I'm now explicitly referring to the post-merge object by But very interestingly, this produces 2:
and I'm at a complete loss as to why. At the very least I think that the fact the third example is inconsistent with the first two is a bug. I'd also argue that Edit: This also works:
output:
Edit 2: After reading #414, I think I understand better some of the difficulties in avoiding making values concrete when doing a mergePatch. However I'm still not sure why my |
This example:
is equivalent to (substitute the x once)
which if you resolve the .a in the middle:
The example with $ is similar:
These self-referential structures allow you to do something which is a bit like late binding, but it's coing from the recursive |
Otherwise, mergePatch is a JSON thing, so your Jsonnet objects are getting resolved to JSON before executing it, which is why |
Ah, that makes perfect sense, thanks.
Since it looks like I'm not the first one to have the wrong expectations here, maybe it's worth explicitly calling this out in the mergePatch documentation? |
Agreed |
For example
RESULTS IN:
Whereas I expected field_to_override to be
override
.The text was updated successfully, but these errors were encountered: