Comprehension inheritance causes syntax error
poweld opened this issue · 2 comments
jrsonnet version: 0.4.2
Using a comprehension to create an inheritable object causes a syntax error within the comprehension.
For example:
{
updateInnerField1:: {
[outerField]+: {
innerField1: "from update",
}
for outerField in ["outerField1"]
},
o1: {
outerField1: {
innerField1: "original",
innerField2: "original",
},
} + $.updateInnerField1,
}
The expected output is:
{
"o1": {
"outerField1": {
"innerField1": "from update",
"innerField2": "original"
}
}
}
but with jrsonnet we hit a syntax error on line 6, column 9 (beginning of the "for" in the comprehension):
syntax error, expected one of one of "(", ".", "[", "{", "}", <binary op>, <whitespace>, got "f"
Changing the line [outerField]+: {
to [outerField]: {
fixes the syntax issue, but of course it changes the results, completely overwriting the object instead of only overwriting the value for innerField1
.
Additionally, unfurling the comprehension also resolves the issue, so it seems like the combination of using a derived field ([outerField]
) and inheritance using +:
causes the issue.
The same syntax error arises when attempting the same but with a list instead of an object:
{
updateOuterField1:: {
[outerField]+: ["from update"],
for outerField in ["outerField1"]
},
o1: {
outerField1: ["original"],
} + $.updateOuterField1,
}
where we expect the output to be
{
"o1": {
"outerField1": [
"original",
"from update"
]
}
}
Thanks for your activity and the error report! Yup, the fix will arrive in 0.5.0
which is currently in its later development phase.