Skip to content

Commit 0ad6826

Browse files
committed
internal/core/adt: initialize erroneous optional fields in disjunctions
When cloning nodeContexts for disjunctions, they must already be initialized to ensure that the closeContext counters stay aligned (especially EVAL). This was enforced by initArcs. initArcs, however, assumed that an error in an arc implied an error in the enclosing arc. This is not true for optional fields. It should therefore still process remaining arcs in these cases. To be safe, we do so for any arc that is not a regular field. Fixes #3680 Signed-off-by: Marcel van Lohuizen <[email protected]> Change-Id: I90763234472ba29c57d71725b57a39186b521458 Reviewed-on: https://gerrithub.io/c/cue-lang/cue/+/1207263 TryBot-Result: CUEcueckoo <[email protected]> Unity-Result: CUE porcuepine <[email protected]> Reviewed-by: Daniel Martí <[email protected]>
1 parent 05f5d76 commit 0ad6826

File tree

2 files changed

+76
-11
lines changed

2 files changed

+76
-11
lines changed

cue/testdata/disjunctions/incomplete.txtar

+68-6
Original file line numberDiff line numberDiff line change
@@ -49,16 +49,31 @@ issue782: {
4949
interpolation: "override"
5050
}
5151
}
52+
-- issue3680.cue --
53+
issue3680: t1: {
54+
{} | {
55+
a?: _|_
56+
b?: _|_
57+
}
58+
{} | {}
59+
}
60+
issue3680: t2: {
61+
x: {} | {
62+
a?: _|_
63+
b?: _|_
64+
}
65+
x: {} | {}
66+
}
5267
-- out/eval/stats --
5368
Leaks: 0
54-
Freed: 70
55-
Reused: 64
56-
Allocs: 6
69+
Freed: 98
70+
Reused: 88
71+
Allocs: 10
5772
Retain: 0
5873

59-
Unifications: 40
60-
Conjuncts: 99
61-
Disjuncts: 70
74+
Unifications: 56
75+
Conjuncts: 132
76+
Disjuncts: 98
6277
-- out/eval --
6378
(struct){
6479
issue700: (struct){
@@ -134,6 +149,32 @@ Disjuncts: 70
134149
interpolation: (string){ "override" }
135150
}
136151
}
152+
issue3680: (struct){
153+
t1: (struct){ |((struct){
154+
}, (struct){
155+
a?: (_|_){
156+
// [user] explicit error (_|_ literal) in source:
157+
// ./issue3680.cue:3:7
158+
}
159+
b?: (_|_){
160+
// [user] explicit error (_|_ literal) in source:
161+
// ./issue3680.cue:4:7
162+
}
163+
}) }
164+
t2: (struct){
165+
x: (struct){ |((struct){
166+
}, (struct){
167+
a?: (_|_){
168+
// [user] explicit error (_|_ literal) in source:
169+
// ./issue3680.cue:10:7
170+
}
171+
b?: (_|_){
172+
// [user] explicit error (_|_ literal) in source:
173+
// ./issue3680.cue:11:7
174+
}
175+
}) }
176+
}
177+
}
137178
}
138179
-- out/compile --
139180
--- in.cue
@@ -186,3 +227,24 @@ Disjuncts: 70
186227
}
187228
}
188229
}
230+
--- issue3680.cue
231+
{
232+
issue3680: {
233+
t1: {
234+
({}|{
235+
a?: _|_(explicit error (_|_ literal) in source)
236+
b?: _|_(explicit error (_|_ literal) in source)
237+
})
238+
({}|{})
239+
}
240+
}
241+
issue3680: {
242+
t2: {
243+
x: ({}|{
244+
a?: _|_(explicit error (_|_ literal) in source)
245+
b?: _|_(explicit error (_|_ literal) in source)
246+
})
247+
x: ({}|{})
248+
}
249+
}
250+
}

internal/core/adt/disjunct2.go

+8-5
Original file line numberDiff line numberDiff line change
@@ -241,16 +241,19 @@ func (n *nodeContext) scheduleDisjunction(d envDisjunct) {
241241
}
242242

243243
func initArcs(ctx *OpContext, v *Vertex) bool {
244+
ok := true
244245
for _, a := range v.Arcs {
245246
s := a.getState(ctx)
246247
if s != nil && s.errs != nil {
247-
return false
248-
}
249-
if !initArcs(ctx, a) {
250-
return false
248+
ok = false
249+
if a.ArcType == ArcMember {
250+
break
251+
}
252+
} else if !initArcs(ctx, a) {
253+
ok = false
251254
}
252255
}
253-
return true
256+
return ok
254257
}
255258

256259
func (n *nodeContext) processDisjunctions() *Bottom {

0 commit comments

Comments
 (0)