internal/core/eval: fix double increase of close ID
This fixes a bug where the close ID could be incremented twice
if a Vertex was added through a disjunction.
Change-Id: I6f161ec2f9bb4e992080c8e831fef55dcdcb56df
Reviewed-on: https://cue-review.googlesource.com/c/cue/+/6646
Reviewed-by: Marcel van Lohuizen <mpvl@golang.org>
diff --git a/internal/core/eval/eval.go b/internal/core/eval/eval.go
index 950f3aa..2121e42 100644
--- a/internal/core/eval/eval.go
+++ b/internal/core/eval/eval.go
@@ -981,7 +981,8 @@
ctx.Unify(ctx, arc, adt.Finalized)
if arc.Label.IsDef() {
- n.insertClosed(arc, cyclic, arc)
+ id := n.eval.nextID()
+ n.insertClosed(arc, id, cyclic, arc)
} else {
for _, a := range arc.Conjuncts {
n.addExprConjunct(updateCyclic(a, cyclic, arc), closeID, top)
@@ -1050,8 +1051,7 @@
return adt.MakeConjunct(env, c.Expr())
}
-func (n *nodeContext) insertClosed(arc *adt.Vertex, cyclic bool, deref *adt.Vertex) {
- id := n.eval.nextID()
+func (n *nodeContext) insertClosed(arc *adt.Vertex, id uint32, cyclic bool, deref *adt.Vertex) {
n.needClose = true
current := n.newClose
@@ -1091,7 +1091,7 @@
if !x.IsData() && len(x.Conjuncts) > 0 {
cyclic := env != nil && env.Cyclic
if needClose {
- n.insertClosed(x, cyclic, nil)
+ n.insertClosed(x, env.CloseID, cyclic, nil)
return
}
for _, c := range x.Conjuncts {