Skip to content

Commit

Permalink
internal/core/adt: catch nil parent
Browse files Browse the repository at this point in the history
In some rare cases a closeContext will not have a parent.
This is currently only the case if Sharing is false.
It is safe to return the input pointers in this case.
In the worst case, it will just limits duplicate
elimination, which will be corrected when a node is
finalized.

Note that this CL has no test. It will be hard, and
perhaps futile, to devise a test that exposes this bug
within the current txtar file setup, because even small
changes in the evaluator may cause this issue to no longer
be exposed. The only way to really expose it is by means
of a unit test. Added a TODO in the function.

Issue #2884
Issue #2851

Signed-off-by: Marcel van Lohuizen <mpvl@gmail.com>
Change-Id: I20bdd0f6488624d1ad384338a9becbf43ab18515
Reviewed-on: https://review.gerrithub.io/c/cue-lang/cue/+/1193672
Reviewed-by: Daniel Martí <mvdan@mvdan.cc>
TryBot-Result: CUEcueckoo <cueckoo@cuelang.org>
Unity-Result: CUE porcuepine <cue.porcuepine@gmail.com>
  • Loading branch information
mpvl committed Apr 23, 2024
1 parent 2ff5afa commit 8087ff7
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions internal/core/adt/disjunct2.go
Original file line number Diff line number Diff line change
Expand Up @@ -590,10 +590,19 @@ func isPartialNode(d *nodeContext) bool {
// Tradeoffs: if we do not go up enough, the two nodes may not be equal and we
// miss the opportunity to filter. On the other hand, if we go up too far, we
// end up comparing more arcs than potentially necessary.
//
// TODO: Add a unit test when this function is fully implemented.
func findIntersections(x, y *closeContext) (cx, cy *closeContext) {
cx = x.parent
cy = y.parent

// TODO: why could this happen? Investigate. Note that it is okay to just
// return x and y. In the worst case we will just miss some possible
// deduplication.
if cx == nil || cy == nil {
return x, y
}

return cx, cy
}

Expand Down

0 comments on commit 8087ff7

Please sign in to comment.