Skip to content

Commit 8908d06

Browse files
committed
cue: add regression test for a cycle error position bug fixed in evalv3
The old evaluator correctly spotted the cycle error in this case, but failed to provide any position. The new evaluator gets it right. Closes #3118. Signed-off-by: Daniel Martí <[email protected]> Change-Id: I6af62a26e10319a6b949aff4ddf8094c646311bf Reviewed-on: https://review.gerrithub.io/c/cue-lang/cue/+/1200092 Unity-Result: CUE porcuepine <[email protected]> TryBot-Result: CUEcueckoo <[email protected]> Reviewed-by: Matthew Sackman <[email protected]>
1 parent 7e29e3d commit 8908d06

File tree

1 file changed

+329
-0
lines changed

1 file changed

+329
-0
lines changed

cue/testdata/cycle/issue3118.txtar

+329
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,329 @@
1+
-- in.cue --
2+
#TimeSpan: {
3+
start: float
4+
duration: float
5+
end: float
6+
7+
start: end - duration
8+
duration: end - start
9+
end: start + duration
10+
11+
start: <=end
12+
}
13+
14+
examples: [string]: #TimeSpan
15+
16+
examples: eg1: {
17+
start: 10.0
18+
duration: 2.1
19+
}
20+
21+
examples: eg2: {
22+
start: 10.0
23+
}
24+
25+
examples: eg3: {
26+
end: 10.0
27+
}
28+
-- out/evalalpha/stats --
29+
Leaks: 19
30+
Freed: 0
31+
Reused: 0
32+
Allocs: 19
33+
Retain: 0
34+
35+
Unifications: 19
36+
Conjuncts: 98
37+
Disjuncts: 0
38+
-- diff/-out/evalalpha/stats<==>+out/eval/stats --
39+
diff old new
40+
--- old
41+
+++ new
42+
@@ -1,9 +1,9 @@
43+
-Leaks: 0
44+
-Freed: 18
45+
-Reused: 12
46+
-Allocs: 6
47+
-Retain: 269
48+
+Leaks: 19
49+
+Freed: 0
50+
+Reused: 0
51+
+Allocs: 19
52+
+Retain: 0
53+
54+
-Unifications: 18
55+
-Conjuncts: 354
56+
-Disjuncts: 19
57+
+Unifications: 19
58+
+Conjuncts: 98
59+
+Disjuncts: 0
60+
-- out/eval/stats --
61+
Leaks: 0
62+
Freed: 18
63+
Reused: 12
64+
Allocs: 6
65+
Retain: 269
66+
67+
Unifications: 18
68+
Conjuncts: 354
69+
Disjuncts: 19
70+
-- out/evalalpha --
71+
(struct){
72+
#TimeSpan: (#struct){
73+
start: (_|_){
74+
// [incomplete] #TimeSpan.start: non-concrete value end for bound <=:
75+
// ./in.cue:10:11
76+
// #TimeSpan.start: non-concrete value float in operand to -:
77+
// ./in.cue:6:12
78+
// ./in.cue:4:12
79+
// #TimeSpan.duration: non-concrete value float in operand to -:
80+
// ./in.cue:7:12
81+
// ./in.cue:4:12
82+
}
83+
duration: (_|_){
84+
// [incomplete] #TimeSpan.start: non-concrete value end for bound <=:
85+
// ./in.cue:10:11
86+
// #TimeSpan.duration: non-concrete value float in operand to -:
87+
// ./in.cue:7:12
88+
// ./in.cue:4:12
89+
}
90+
end: (_|_){
91+
// [incomplete] #TimeSpan.start: non-concrete value end for bound <=:
92+
// ./in.cue:10:11
93+
// #TimeSpan.start: non-concrete value float in operand to -:
94+
// ./in.cue:6:12
95+
// ./in.cue:4:12
96+
// #TimeSpan.duration: non-concrete value float in operand to -:
97+
// ./in.cue:7:12
98+
// ./in.cue:4:12
99+
}
100+
}
101+
examples: (struct){
102+
eg1: (#struct){
103+
start: (float){ 10.0 }
104+
duration: (float){ 2.1 }
105+
end: (float){ 12.1 }
106+
}
107+
eg2: (#struct){
108+
start: (_|_){
109+
// [incomplete] examples.eg2.start: non-concrete value end for bound <=:
110+
// ./in.cue:10:11
111+
// examples.eg2.duration: non-concrete value float in operand to -:
112+
// ./in.cue:7:12
113+
// ./in.cue:4:12
114+
}
115+
duration: (_|_){
116+
// [incomplete] examples.eg2.start: non-concrete value end for bound <=:
117+
// ./in.cue:10:11
118+
// examples.eg2.duration: non-concrete value float in operand to -:
119+
// ./in.cue:7:12
120+
// ./in.cue:4:12
121+
}
122+
end: (_|_){
123+
// [incomplete] examples.eg2.start: non-concrete value end for bound <=:
124+
// ./in.cue:10:11
125+
// examples.eg2.duration: non-concrete value float in operand to -:
126+
// ./in.cue:7:12
127+
// ./in.cue:4:12
128+
}
129+
}
130+
eg3: (#struct){
131+
end: (_|_){
132+
// [incomplete] examples.eg3.duration: non-concrete value <=10.0 & float in operand to -:
133+
// ./in.cue:7:12
134+
// ./in.cue:10:9
135+
}
136+
start: (_|_){
137+
// [incomplete] examples.eg3.duration: non-concrete value <=10.0 & float in operand to -:
138+
// ./in.cue:7:12
139+
// ./in.cue:10:9
140+
}
141+
duration: (_|_){
142+
// [incomplete] examples.eg3.duration: non-concrete value <=10.0 & float in operand to -:
143+
// ./in.cue:7:12
144+
// ./in.cue:10:9
145+
}
146+
}
147+
}
148+
}
149+
-- diff/explanation --
150+
the new evaluator includes positions with the cycle error and the old evaluator does not.
151+
-- diff/-out/evalalpha<==>+out/eval --
152+
diff old new
153+
--- old
154+
+++ new
155+
@@ -1,15 +1,31 @@
156+
(struct){
157+
#TimeSpan: (#struct){
158+
start: (_|_){
159+
- // [cycle] cycle error
160+
+ // [incomplete] #TimeSpan.start: non-concrete value end for bound <=:
161+
+ // ./in.cue:10:11
162+
+ // #TimeSpan.start: non-concrete value float in operand to -:
163+
+ // ./in.cue:6:12
164+
+ // ./in.cue:4:12
165+
+ // #TimeSpan.duration: non-concrete value float in operand to -:
166+
+ // ./in.cue:7:12
167+
+ // ./in.cue:4:12
168+
}
169+
duration: (_|_){
170+
- // [cycle] cycle error:
171+
- // ./in.cue:7:12
172+
+ // [incomplete] #TimeSpan.start: non-concrete value end for bound <=:
173+
+ // ./in.cue:10:11
174+
+ // #TimeSpan.duration: non-concrete value float in operand to -:
175+
+ // ./in.cue:7:12
176+
+ // ./in.cue:4:12
177+
}
178+
end: (_|_){
179+
- // [cycle] cycle error:
180+
- // ./in.cue:8:12
181+
+ // [incomplete] #TimeSpan.start: non-concrete value end for bound <=:
182+
+ // ./in.cue:10:11
183+
+ // #TimeSpan.start: non-concrete value float in operand to -:
184+
+ // ./in.cue:6:12
185+
+ // ./in.cue:4:12
186+
+ // #TimeSpan.duration: non-concrete value float in operand to -:
187+
+ // ./in.cue:7:12
188+
+ // ./in.cue:4:12
189+
}
190+
}
191+
examples: (struct){
192+
@@ -20,26 +36,42 @@
193+
}
194+
eg2: (#struct){
195+
start: (_|_){
196+
- // [cycle] cycle error
197+
- }
198+
- duration: (_|_){
199+
- // [cycle] cycle error:
200+
- // ./in.cue:7:12
201+
- }
202+
- end: (_|_){
203+
- // [cycle] cycle error
204+
+ // [incomplete] examples.eg2.start: non-concrete value end for bound <=:
205+
+ // ./in.cue:10:11
206+
+ // examples.eg2.duration: non-concrete value float in operand to -:
207+
+ // ./in.cue:7:12
208+
+ // ./in.cue:4:12
209+
+ }
210+
+ duration: (_|_){
211+
+ // [incomplete] examples.eg2.start: non-concrete value end for bound <=:
212+
+ // ./in.cue:10:11
213+
+ // examples.eg2.duration: non-concrete value float in operand to -:
214+
+ // ./in.cue:7:12
215+
+ // ./in.cue:4:12
216+
+ }
217+
+ end: (_|_){
218+
+ // [incomplete] examples.eg2.start: non-concrete value end for bound <=:
219+
+ // ./in.cue:10:11
220+
+ // examples.eg2.duration: non-concrete value float in operand to -:
221+
+ // ./in.cue:7:12
222+
+ // ./in.cue:4:12
223+
}
224+
}
225+
eg3: (#struct){
226+
end: (_|_){
227+
- // [cycle] cycle error:
228+
- // ./in.cue:8:12
229+
- }
230+
- start: (_|_){
231+
- // [cycle] cycle error
232+
- }
233+
- duration: (_|_){
234+
- // [cycle] cycle error
235+
+ // [incomplete] examples.eg3.duration: non-concrete value <=10.0 & float in operand to -:
236+
+ // ./in.cue:7:12
237+
+ // ./in.cue:10:9
238+
+ }
239+
+ start: (_|_){
240+
+ // [incomplete] examples.eg3.duration: non-concrete value <=10.0 & float in operand to -:
241+
+ // ./in.cue:7:12
242+
+ // ./in.cue:10:9
243+
+ }
244+
+ duration: (_|_){
245+
+ // [incomplete] examples.eg3.duration: non-concrete value <=10.0 & float in operand to -:
246+
+ // ./in.cue:7:12
247+
+ // ./in.cue:10:9
248+
}
249+
}
250+
}
251+
-- out/eval --
252+
(struct){
253+
#TimeSpan: (#struct){
254+
start: (_|_){
255+
// [cycle] cycle error
256+
}
257+
duration: (_|_){
258+
// [cycle] cycle error:
259+
// ./in.cue:7:12
260+
}
261+
end: (_|_){
262+
// [cycle] cycle error:
263+
// ./in.cue:8:12
264+
}
265+
}
266+
examples: (struct){
267+
eg1: (#struct){
268+
start: (float){ 10.0 }
269+
duration: (float){ 2.1 }
270+
end: (float){ 12.1 }
271+
}
272+
eg2: (#struct){
273+
start: (_|_){
274+
// [cycle] cycle error
275+
}
276+
duration: (_|_){
277+
// [cycle] cycle error:
278+
// ./in.cue:7:12
279+
}
280+
end: (_|_){
281+
// [cycle] cycle error
282+
}
283+
}
284+
eg3: (#struct){
285+
end: (_|_){
286+
// [cycle] cycle error:
287+
// ./in.cue:8:12
288+
}
289+
start: (_|_){
290+
// [cycle] cycle error
291+
}
292+
duration: (_|_){
293+
// [cycle] cycle error
294+
}
295+
}
296+
}
297+
}
298+
-- out/compile --
299+
--- in.cue
300+
{
301+
#TimeSpan: {
302+
start: float
303+
duration: float
304+
end: float
305+
start: (〈0;end〉 - 〈0;duration〉)
306+
duration: (〈0;end〉 - 〈0;start〉)
307+
end: (〈0;start〉 + 〈0;duration〉)
308+
start: <=〈0;end〉
309+
}
310+
examples: {
311+
[string]: 〈1;#TimeSpan〉
312+
}
313+
examples: {
314+
eg1: {
315+
start: 10.0
316+
duration: 2.1
317+
}
318+
}
319+
examples: {
320+
eg2: {
321+
start: 10.0
322+
}
323+
}
324+
examples: {
325+
eg3: {
326+
end: 10.0
327+
}
328+
}
329+
}

0 commit comments

Comments
 (0)