google/jsonnet

adjacent object literals vs adjacent variables

dcopso opened this issue · 2 comments

dcopso commented

I'm new to jsonnet and I'm loving it but I see a behavior that I'm surprised by: the + between object literals seems to be optional, but only on object literals:

This program is valid:

{a:1} {b:1}

This program is not:

local left = {a:1};
local right = {b:1};
left right

Changing left right to left + right makes the program valid.

This suggests that variables are not transparent in the same way that functions are. Is this expected?

Also, what is going on with {a:1} {b:1}? Why is that, and expressions such as {}{}, valid?

Thanks!

dcopso commented

This has also been raised in the discussion forum: https://groups.google.com/g/jsonnet/c/RoJIt5vlwX4

This is sugar for object coming right after any other expression, it desugars to a + b

Relevant part of the specification:
$desugar_{expr}(e { objinside }, b) = desugar_{expr}(e + { objinside }, b)$