Skip to content

Commit be2ee9b

Browse files
committed
internal/core/adt: prevent state inversion
Prevent evaluting with a lower state than requested. Also make ForClause request Finalized: with the upcoming comprehension changes this is needed to elminate void arcs. Change-Id: I95bf5db80265dd7a12e9015c13429c9ff505a97b Signed-off-by: Marcel van Lohuizen <mpvl@golang.org> Reviewed-on: https://review.gerrithub.io/c/cue-lang/cue/+/533224 Unity-Result: CUEcueckoo <cueckoo@cuelang.org> TryBot-Result: CUEcueckoo <cueckoo@cuelang.org> Reviewed-by: Marcel van Lohuizen <mpvl@gmail.com>
1 parent e499dae commit be2ee9b

File tree

4 files changed

+30
-22
lines changed

4 files changed

+30
-22
lines changed

cue/testdata/builtins/incomplete.txtar

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -116,26 +116,26 @@ Result:
116116
list1: (struct){
117117
Out1: (#list){
118118
0: (_|_){
119-
// [cycle] cycle error:
120-
// ./in.cue:17:23
119+
// [incomplete] list1._Sub: undefined field: b:
120+
// ./in.cue:20:13
121121
}
122122
}
123123
Out2: (#list){
124124
0: (_|_){
125-
// [cycle] cycle error:
126-
// ./in.cue:17:23
125+
// [incomplete] list1._Sub: undefined field: b:
126+
// ./in.cue:20:13
127127
}
128128
}
129129
Out3: (#list){
130130
0: (_|_){
131-
// [cycle] cycle error:
132-
// ./in.cue:17:23
131+
// [incomplete] list1._Sub: undefined field: b:
132+
// ./in.cue:20:13
133133
}
134134
}
135135
Top: (#list){
136136
0: (_|_){
137-
// [cycle] cycle error:
138-
// ./in.cue:17:23
137+
// [incomplete] list1._Sub: undefined field: b:
138+
// ./in.cue:20:13
139139
}
140140
}
141141
_Sub: (_|_){
@@ -147,20 +147,20 @@ Result:
147147
}
148148
list2: (struct){
149149
Out1: (_|_){
150-
// [cycle] cycle error:
151-
// ./in.cue:31:21
150+
// [incomplete] list2.#Sub: undefined field: b:
151+
// ./in.cue:34:13
152152
}
153153
Out2: (_|_){
154-
// [cycle] cycle error:
155-
// ./in.cue:31:21
154+
// [incomplete] list2.#Sub: undefined field: b:
155+
// ./in.cue:34:13
156156
}
157157
Out3: (_|_){
158-
// [cycle] cycle error:
159-
// ./in.cue:31:21
158+
// [incomplete] list2.#Sub: undefined field: b:
159+
// ./in.cue:34:13
160160
}
161161
_Top: (_|_){
162-
// [cycle] cycle error:
163-
// ./in.cue:31:21
162+
// [incomplete] list2.#Sub: undefined field: b:
163+
// ./in.cue:34:13
164164
}
165165
#Sub: (_|_){
166166
// [incomplete] list2.#Sub: undefined field: b:

cue/testdata/eval/closedness.txtar

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ a.q: field not allowed: e:
5252
./in.cue:11:4
5353
./in.cue:15:9
5454
issue852.a: field not allowed: Foo:
55+
./in.cue:30:15
5556
./in.cue:22:7
5657
./in.cue:26:6
5758
./in.cue:28:6
@@ -87,21 +88,23 @@ Result:
8788
}
8889
}
8990
issue852: (_|_){
90-
// [eval]
91+
// [eval] issue852.a: field not allowed: Foo:
92+
// ./in.cue:30:15
93+
// ./in.cue:22:7
94+
// ./in.cue:26:6
95+
// ./in.cue:28:6
9196
#A: (#struct){
9297
}
9398
a: (_|_){
9499
// [eval]
95100
Foo: (_|_){
96101
// [eval] issue852.a: field not allowed: Foo:
102+
// ./in.cue:30:15
97103
// ./in.cue:22:7
98104
// ./in.cue:26:6
99105
// ./in.cue:28:6
100106
}
101107
}
102-
b: (struct){
103-
Foo: (string){ "foo" }
104-
}
105108
}
106109
dynamic: (struct){
107110
#D: (#struct){

internal/core/adt/context.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -695,8 +695,13 @@ func (c *OpContext) unifyNode(v Expr, state VertexStatus) (result Value) {
695695
}
696696

697697
if v.isUndefined() {
698+
// Keep a minimum state of AllArcs.
699+
state := state
700+
if state < AllArcs {
701+
state = AllArcs
702+
}
698703
// Use node itself to allow for cycle detection.
699-
c.Unify(v, AllArcs)
704+
c.Unify(v, state)
700705
}
701706

702707
return v

internal/core/adt/expr.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1637,7 +1637,7 @@ func (x *ForClause) Source() ast.Node {
16371637
}
16381638

16391639
func (x *ForClause) yield(c *OpContext, f YieldFunc) {
1640-
n := c.node(x, x.Src, true, AllArcs)
1640+
n := c.node(x, x.Src, true, Finalized)
16411641
for _, a := range n.Arcs {
16421642
if !a.Label.IsRegular() {
16431643
continue

0 commit comments

Comments
 (0)