-
Notifications
You must be signed in to change notification settings - Fork 248
Open
Description
I expect the following two snippets to be equivalent:
local base = {
a: 10,
withADecremented:: function() self { a: super.a - 1 },
};
base { b: 20 }.withADecremented()
(implicit plus in the last line)
local base = {
a: 10,
withADecremented:: function() self { a: super.a - 1 },
};
base + { b: 20 }.withADecremented()
(explicit plus in the last line)
However, the first one successfully compiles to { a: 9, b: 20 } while the second fails:
RUNTIME ERROR: Field does not exist: withADecremented
services/examples/example.jsonnet:5:8-34 $
During evaluation
Documentation of implicit plus is scarce but the following sentence in jsonnet.org/learning/tutorial.html:
In the common case where you write foo + { ... }, i.e. the + is immediately followed by a {, then the + can be elided.
and the existence of the (no-)use-implicit-plus jsonnetfmt CLI option together suggest that foo {} is syntactic sugar for foo + {}. In fact the two appear to bind at different precedence compared to . as shown by the above example.
Metadata
Metadata
Assignees
Labels
No labels