Skip to content

Commit 9e9786e

Browse files
committed
internal/core/adt: defensive use of CloseInfo
Passing CloseInfo in some cases where it doesn't seem to be necessary. Signed-off-by: Marcel van Lohuizen <[email protected]> Change-Id: Ia3fc729fe951d227a05b9af40e6c4d49155af3f6 Reviewed-on: https://review.gerrithub.io/c/cue-lang/cue/+/542831 Unity-Result: CUEcueckoo <[email protected]> TryBot-Result: CUEcueckoo <[email protected]> Reviewed-by: Paul Jolly <[email protected]>
1 parent 3290797 commit 9e9786e

File tree

5 files changed

+76
-13
lines changed

5 files changed

+76
-13
lines changed

Diff for: cue/testdata/cycle/evaluate.txtar

+69-8
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,18 @@ embedCycle: {
5454
c: a
5555
}
5656

57+
listAddCycle: {
58+
a: b
59+
b: [c] + [c]
60+
c: a
61+
}
62+
63+
listMulCycle: {
64+
a: b
65+
b: 3 + [{a: b: c}]
66+
c: a
67+
}
68+
5769
// consult the correct closeness info in the face of it being passed down
5870
// from parent.
5971
closeFail: {
@@ -67,10 +79,10 @@ Errors:
6779
closeCycle.a: structural cycle
6880
closeCycle.b.d: structural cycle
6981
closeFail.x.b: field not allowed:
70-
./in.cue:59:6
71-
./in.cue:60:12
72-
./in.cue:61:6
73-
./in.cue:62:5
82+
./in.cue:71:6
83+
./in.cue:72:12
84+
./in.cue:73:6
85+
./in.cue:74:5
7486
listCycle.0: structural cycle:
7587
./in.cue:17:9
7688
disjunctionCycle.a: cannot use 1 (type int) as list in argument 1 to and:
@@ -91,6 +103,8 @@ structCycle.0.d: structural cycle:
91103
./in.cue:46:9
92104
embedCycle: structural cycle:
93105
./in.cue:52:11
106+
listAddCycle.0: structural cycle:
107+
./in.cue:58:5
94108

95109
Result:
96110
(_|_){
@@ -209,6 +223,33 @@ Result:
209223
// ./in.cue:52:11
210224
}
211225
}
226+
listAddCycle: (_|_){
227+
// [structural cycle]
228+
a: (_|_){
229+
// [structural cycle] listAddCycle.0: structural cycle:
230+
// ./in.cue:58:5
231+
}
232+
b: (_|_){
233+
// [structural cycle] listAddCycle.0: structural cycle:
234+
// ./in.cue:58:5
235+
}
236+
c: (_|_){
237+
// [structural cycle] listAddCycle.0: structural cycle:
238+
// ./in.cue:58:5
239+
}
240+
}
241+
listMulCycle: (_|_){
242+
// [structural cycle]
243+
a: (_|_){
244+
// [structural cycle]
245+
}
246+
b: (_|_){
247+
// [structural cycle]
248+
}
249+
c: (_|_){
250+
// [structural cycle]
251+
}
252+
}
212253
closeFail: (_|_){
213254
// [eval]
214255
#T: (#struct){
@@ -219,10 +260,10 @@ Result:
219260
a: (string){ string }
220261
b: (_|_){
221262
// [eval] closeFail.x.b: field not allowed:
222-
// ./in.cue:59:6
223-
// ./in.cue:60:12
224-
// ./in.cue:61:6
225-
// ./in.cue:62:5
263+
// ./in.cue:71:6
264+
// ./in.cue:72:12
265+
// ./in.cue:73:6
266+
// ./in.cue:74:5
226267
}
227268
}
228269
}
@@ -290,6 +331,26 @@ Result:
290331
})
291332
c: 〈0;a〉
292333
}
334+
listAddCycle: {
335+
a: 〈0;b〉
336+
b: ([
337+
〈1;c〉,
338+
] + [
339+
〈1;c〉,
340+
])
341+
c: 〈0;a〉
342+
}
343+
listMulCycle: {
344+
a: 〈0;b〉
345+
b: (3 + [
346+
{
347+
a: {
348+
b: 〈3;c〉
349+
}
350+
},
351+
])
352+
c: 〈0;a〉
353+
}
293354
closeFail: {
294355
#T: {
295356
[_]: _

Diff for: internal/core/adt/binop.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ func BinOp(c *OpContext, op Op, left, right Value) Value {
205205
}
206206

207207
n := &Vertex{}
208-
n.AddConjunct(MakeRootConjunct(c.Env(0), list))
208+
n.AddConjunct(MakeConjunct(c.Env(0), list, c.ci))
209209
n.Finalize(c)
210210

211211
return n
@@ -266,7 +266,7 @@ func BinOp(c *OpContext, op Op, left, right Value) Value {
266266
}
267267

268268
n := &Vertex{}
269-
n.AddConjunct(MakeRootConjunct(c.Env(0), list))
269+
n.AddConjunct(MakeConjunct(c.Env(0), list, c.ci))
270270
n.Finalize(c)
271271

272272
return n

Diff for: internal/core/adt/context.go

+2
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,8 @@ type OpContext struct {
255255
inConstraint int
256256
}
257257

258+
func (c *OpContext) CloseInfo() CloseInfo { return c.ci }
259+
258260
func (n *nodeContext) skipNonMonotonicChecks() bool {
259261
if n.ctx.inConstraint > 0 {
260262
return false

Diff for: internal/core/adt/eval.go

+1-2
Original file line numberDiff line numberDiff line change
@@ -2018,8 +2018,7 @@ func (n *nodeContext) addLists() (oneOfTheLists Expr, anID CloseInfo) {
20182018

20192019
for _, a := range elems {
20202020
if a.Conjuncts == nil {
2021-
x := a.BaseValue.(Value)
2022-
n.insertField(a.Label, MakeRootConjunct(nil, x))
2021+
n.insertField(a.Label, MakeRootConjunct(nil, a))
20232022
continue
20242023
}
20252024
for _, c := range a.Conjuncts {

Diff for: internal/core/compile/builtin.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -137,8 +137,9 @@ var orBuiltin = &adt.Builtin{
137137
}
138138
v := &adt.Vertex{}
139139
// TODO: make a Disjunction.
140-
v.AddConjunct(adt.MakeRootConjunct(nil,
140+
v.AddConjunct(adt.MakeConjunct(nil,
141141
&adt.DisjunctionExpr{Values: d, HasDefaults: false},
142+
c.CloseInfo(),
142143
))
143144
c.Unify(v, adt.Finalized)
144145
return v

0 commit comments

Comments
 (0)