diff --git a/builtins.go b/builtins.go index cc66696..9f22371 100644 --- a/builtins.go +++ b/builtins.go @@ -777,7 +777,7 @@ func builtinSplitLimit(i *interpreter, trace TraceElement, strv, cv, maxSplitsV if maxSplits == -1 { strs = strings.SplitN(sStr, sC, -1) } else { - strs = strings.SplitN(sStr, sC, maxSplits + 1) + strs = strings.SplitN(sStr, sC, maxSplits+1) } res := make([]*cachedThunk, len(strs)) for i := range strs { @@ -821,8 +821,7 @@ func builtinUglyObjectFlatMerge(i *interpreter, trace TraceElement, x value) (va return &valueSimpleObject{}, nil } newFields := make(simpleObjectFieldMap) - var locals []objectLocal - var upValues bindingFrame + var anyObj *valueSimpleObject for _, elem := range objarr.elements { obj, err := i.evaluateObject(elem, trace) if err != nil { @@ -853,14 +852,22 @@ func builtinUglyObjectFlatMerge(i *interpreter, trace TraceElement, x value) (va bindings: simpleObj.upValues, }, } - // another ugliness - we just take the locals of our last object, - // we assume that the locals are the same for each of merged objects - locals = simpleObj.locals } + anyObj = simpleObj + } + + var locals []objectLocal + var localUpValues bindingFrame + if len(objarr.elements) > 0 { + // another ugliness - we just take the locals of our last object, + // we assume that the locals are the same for each of merged objects + locals = anyObj.locals + // note that there are already holes for object locals + localUpValues = anyObj.upValues } return makeValueSimpleObject( - upValues, + localUpValues, newFields, []unboundField{}, // No asserts allowed locals, diff --git a/testdata/object_comp_local.golden b/testdata/object_comp_local.golden new file mode 100644 index 0000000..126cb2c --- /dev/null +++ b/testdata/object_comp_local.golden @@ -0,0 +1,3 @@ +{ + "a": "170b" +} diff --git a/testdata/object_comp_local.jsonnet b/testdata/object_comp_local.jsonnet new file mode 100644 index 0000000..db82588 --- /dev/null +++ b/testdata/object_comp_local.jsonnet @@ -0,0 +1 @@ +local a = "b"; {local tmp = a, [name]: std.parseHex("aa") + tmp for name in ["a"]} \ No newline at end of file diff --git a/testdata/object_comp_local2.golden b/testdata/object_comp_local2.golden new file mode 100644 index 0000000..7e027be --- /dev/null +++ b/testdata/object_comp_local2.golden @@ -0,0 +1,3 @@ +{ + "a": 425 +} diff --git a/testdata/object_comp_local2.jsonnet b/testdata/object_comp_local2.jsonnet new file mode 100644 index 0000000..89d7155 --- /dev/null +++ b/testdata/object_comp_local2.jsonnet @@ -0,0 +1 @@ +{local tmp = std.parseHex("ff"), [name]: std.parseHex("aa") + tmp for name in ["a"]} \ No newline at end of file diff --git a/testdata/object_comp_local3.golden b/testdata/object_comp_local3.golden new file mode 100644 index 0000000..ac4cd93 --- /dev/null +++ b/testdata/object_comp_local3.golden @@ -0,0 +1,3 @@ +{ + "a": 255 +} diff --git a/testdata/object_comp_local3.jsonnet b/testdata/object_comp_local3.jsonnet new file mode 100644 index 0000000..5d43bd3 --- /dev/null +++ b/testdata/object_comp_local3.jsonnet @@ -0,0 +1 @@ +{local tmp = std.parseHex("ff"), [name]: tmp for name in ["a"]} \ No newline at end of file