Open
Description
I was actually trying to use an object comprehension with a top level function, like:
function(j) {
local obj = std.parseJson(j),
[key]: someOtherFunction(key)
for key in std.objectFields(obj)
}
But then I was able to minimize the reproducer to:
{
local x = ['a'],
[key]: key
for key in x
}
Which errors with
/tmp/f.jsonnet:5:14-15 Unknown variable: x
for key in x
I expected this form to work.
If this is behaving as intended, perhaps there is a way the error message could be improved?
Eventually I figured out that I can move the local variable declaration outside of the scope of the object comprehension:
(
local x = ['a'];
{
[key]: key
for key in x
}
)
Which results in
{
"a": "a"
}
as expected. But this approach was very unintuitive and took me around 45 minutes to debug, even though I've been working with Jsonnet on a near-daily basis for 6+ months.