Use baseValue from source in binOp to make gc working
Fixes #184
`binSrc(src.Pos(), op, x, other)` will hold reference to `left` and `right` variables which will prevent them from gc.
Closes #188
https://github.com/cuelang/cue/pull/188
GitOrigin-RevId: e9af654f0b9805b6db5d027575c523d09bc4b066
Change-Id: I740c0847fe4c7446ec5c0823aca1ede10bf1dd21
Reviewed-on: https://cue-review.googlesource.com/c/cue/+/4181
Reviewed-by: Marcel van Lohuizen <mpvl@golang.org>
diff --git a/cue/binop.go b/cue/binop.go
index b880159..86dca45 100644
--- a/cue/binop.go
+++ b/cue/binop.go
@@ -625,14 +625,20 @@
return x
}
arcs := make(arcs, 0, len(x.arcs)+len(y.arcs))
+ var base baseValue
+ if src.computed() != nil {
+ base = baseValue{src.computed()}
+ } else {
+ base = binSrc(src.Pos(), op, x, other)
+ }
obj := &structLit{
- binSrc(src.Pos(), op, x, other), // baseValue
- x.emit, // emit
- nil, // template
- x.closeStatus | y.closeStatus, // closeStatus
- nil, // comprehensions
- arcs, // arcs
- nil, // attributes
+ base, // baseValue
+ x.emit, // emit
+ nil, // template
+ x.closeStatus | y.closeStatus, // closeStatus
+ nil, // comprehensions
+ arcs, // arcs
+ nil, // attributes
}
defer ctx.pushForwards(x, obj, y, obj).popForwards()