internal/core/adt: prevent early decrements in comprehensions
Pending arcs in comprehensions follow a slightly
different code path and are evaluated a bit earlier
to determine whether the fields will exist.
We need to ensure that if a "complete all" path is
agitated, we do not break incoming dependencies
if we are not finalizing. Doing so might cause the
closeContexts to be closed, causing an "already
closed" panic when a matching pattern constraint
is later evaluated.
We enforce this by requiring `breakIncomingDeps`
to take the current mode and then only commence
when mode is finalize.
Note that there are two call sites. We added two
test cases, the reported one and a variant, each of
which triggered a panic for the respective code paths.
Fixes #3691
Signed-off-by: Marcel van Lohuizen <mpvl@gmail.com>
Change-Id: Ib4e9dda97a002f2ac5f96f4b31985e6c7ddb4f07
Reviewed-on: https://review.gerrithub.io/c/cue-lang/cue/+/1207545
Reviewed-by: Daniel Martí <mvdan@mvdan.cc>
Unity-Result: CUE porcuepine <cue.porcuepine@gmail.com>
TryBot-Result: CUEcueckoo <cueckoo@cuelang.org>