mirror of
https://github.com/google/go-jsonnet.git
synced 2025-08-07 14:57:24 +02:00
Proper env for obj locals in comprehensions
We didn't set the environment (upvalues) for objects created as comprehensions - we set them for each field separately, but that meant missing the locals.
This commit is contained in:
parent
33b6dcfa53
commit
83ed0b939f
21
builtins.go
21
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,
|
||||
|
3
testdata/object_comp_local.golden
vendored
Normal file
3
testdata/object_comp_local.golden
vendored
Normal file
@ -0,0 +1,3 @@
|
||||
{
|
||||
"a": "170b"
|
||||
}
|
1
testdata/object_comp_local.jsonnet
vendored
Normal file
1
testdata/object_comp_local.jsonnet
vendored
Normal file
@ -0,0 +1 @@
|
||||
local a = "b"; {local tmp = a, [name]: std.parseHex("aa") + tmp for name in ["a"]}
|
3
testdata/object_comp_local2.golden
vendored
Normal file
3
testdata/object_comp_local2.golden
vendored
Normal file
@ -0,0 +1,3 @@
|
||||
{
|
||||
"a": 425
|
||||
}
|
1
testdata/object_comp_local2.jsonnet
vendored
Normal file
1
testdata/object_comp_local2.jsonnet
vendored
Normal file
@ -0,0 +1 @@
|
||||
{local tmp = std.parseHex("ff"), [name]: std.parseHex("aa") + tmp for name in ["a"]}
|
3
testdata/object_comp_local3.golden
vendored
Normal file
3
testdata/object_comp_local3.golden
vendored
Normal file
@ -0,0 +1,3 @@
|
||||
{
|
||||
"a": 255
|
||||
}
|
1
testdata/object_comp_local3.jsonnet
vendored
Normal file
1
testdata/object_comp_local3.jsonnet
vendored
Normal file
@ -0,0 +1 @@
|
||||
{local tmp = std.parseHex("ff"), [name]: tmp for name in ["a"]}
|
Loading…
Reference in New Issue
Block a user