Skip to content

Commit

Permalink
internal/core/eval: fix double increase of close ID
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
mpvl committed Jul 23, 2020
1 parent 76d8c61 commit 3acdde8
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions internal/core/eval/eval.go
Original file line number Diff line number Diff line change
Expand Up @@ -981,7 +981,8 @@ outer:
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)
Expand Down Expand Up @@ -1050,8 +1051,7 @@ func updateCyclic(c adt.Conjunct, cyclic bool, deref *adt.Vertex) adt.Conjunct {
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
Expand Down Expand Up @@ -1091,7 +1091,7 @@ func (n *nodeContext) addValueConjunct(env *adt.Environment, v adt.Value) {
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 {
Expand Down

0 comments on commit 3acdde8

Please sign in to comment.