Skip to content

Commit f23e3d5

Browse files
committed
internal/core/adt: only set scalar if not already defined
Not doing so could result in a bug where an error was erased. This would only be exposed by CLs that will be submitted later. Note that "cyclic" denotes the inprogress marker and means "not set". Issue #2169 Signed-off-by: Marcel van Lohuizen <[email protected]> Change-Id: I8e7c5b504fd21cd193eec7c981eed6bd8ce34868 Reviewed-on: https://review.gerrithub.io/c/cue-lang/cue/+/548904 Reviewed-by: Roger Peppe <[email protected]> Reviewed-by: Daniel Martí <[email protected]> Unity-Result: CUEcueckoo <[email protected]> TryBot-Result: CUEcueckoo <[email protected]>
1 parent b75fdc8 commit f23e3d5

File tree

2 files changed

+12
-12
lines changed

2 files changed

+12
-12
lines changed

cue/testdata/cycle/inline.txtar

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -153,15 +153,15 @@ inline: acrossFields: ok1: {
153153
}
154154
}
155155
-- out/eval/stats --
156-
Leaks: 268
157-
Freed: 168
158-
Reused: 162
159-
Allocs: 274
160-
Retain: 821
156+
Leaks: 247
157+
Freed: 141
158+
Reused: 136
159+
Allocs: 252
160+
Retain: 734
161161

162-
Unifications: 436
163-
Conjuncts: 1499
164-
Disjuncts: 795
162+
Unifications: 388
163+
Conjuncts: 1297
164+
Disjuncts: 688
165165
-- out/eval --
166166
Errors:
167167
structural cycle:

internal/core/adt/eval.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,7 @@ func (c *OpContext) Unify(v *Vertex, state VertexStatus) {
235235
fallthrough
236236

237237
case Partial, Conjuncts:
238+
// TODO: remove this optimization or make it correct.
238239
// No need to do further processing when we have errors and all values
239240
// have been considered.
240241
// TODO: is checkClosed really still necessary here?
@@ -1348,10 +1349,9 @@ func (n *nodeContext) getValidators(state VertexStatus) BaseValue {
13481349

13491350
// TODO: this function can probably go as this is now handled in the nodeContext.
13501351
func (n *nodeContext) maybeSetCache() {
1351-
if n.node.Status() > Partial { // n.node.BaseValue != nil
1352-
return
1353-
}
1354-
if n.scalar != nil {
1352+
// Set BaseValue to scalar, but only if it was not set before. Most notably,
1353+
// errors should not be discarded.
1354+
if n.scalar != nil && isCyclePlaceholder(n.node.BaseValue) {
13551355
n.node.BaseValue = n.scalar
13561356
}
13571357
// NOTE: this is now handled by associating the nodeContext

0 commit comments

Comments
 (0)