From 8908d06c984fe222417e8c46df57fe8b2075a26a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Mart=C3=AD?= Date: Tue, 27 Aug 2024 16:12:32 +0100 Subject: [PATCH] cue: add regression test for a cycle error position bug fixed in evalv3 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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í Change-Id: I6af62a26e10319a6b949aff4ddf8094c646311bf Reviewed-on: https://review.gerrithub.io/c/cue-lang/cue/+/1200092 Unity-Result: CUE porcuepine TryBot-Result: CUEcueckoo Reviewed-by: Matthew Sackman --- cue/testdata/cycle/issue3118.txtar | 329 +++++++++++++++++++++++++++++ 1 file changed, 329 insertions(+) create mode 100644 cue/testdata/cycle/issue3118.txtar diff --git a/cue/testdata/cycle/issue3118.txtar b/cue/testdata/cycle/issue3118.txtar new file mode 100644 index 00000000000..91dcdb8602c --- /dev/null +++ b/cue/testdata/cycle/issue3118.txtar @@ -0,0 +1,329 @@ +-- in.cue -- +#TimeSpan: { + start: float + duration: float + end: float + + start: end - duration + duration: end - start + end: start + duration + + start: <=end +} + +examples: [string]: #TimeSpan + +examples: eg1: { + start: 10.0 + duration: 2.1 +} + +examples: eg2: { + start: 10.0 +} + +examples: eg3: { + end: 10.0 +} +-- out/evalalpha/stats -- +Leaks: 19 +Freed: 0 +Reused: 0 +Allocs: 19 +Retain: 0 + +Unifications: 19 +Conjuncts: 98 +Disjuncts: 0 +-- diff/-out/evalalpha/stats<==>+out/eval/stats -- +diff old new +--- old ++++ new +@@ -1,9 +1,9 @@ +-Leaks: 0 +-Freed: 18 +-Reused: 12 +-Allocs: 6 +-Retain: 269 ++Leaks: 19 ++Freed: 0 ++Reused: 0 ++Allocs: 19 ++Retain: 0 + +-Unifications: 18 +-Conjuncts: 354 +-Disjuncts: 19 ++Unifications: 19 ++Conjuncts: 98 ++Disjuncts: 0 +-- out/eval/stats -- +Leaks: 0 +Freed: 18 +Reused: 12 +Allocs: 6 +Retain: 269 + +Unifications: 18 +Conjuncts: 354 +Disjuncts: 19 +-- out/evalalpha -- +(struct){ + #TimeSpan: (#struct){ + start: (_|_){ + // [incomplete] #TimeSpan.start: non-concrete value end for bound <=: + // ./in.cue:10:11 + // #TimeSpan.start: non-concrete value float in operand to -: + // ./in.cue:6:12 + // ./in.cue:4:12 + // #TimeSpan.duration: non-concrete value float in operand to -: + // ./in.cue:7:12 + // ./in.cue:4:12 + } + duration: (_|_){ + // [incomplete] #TimeSpan.start: non-concrete value end for bound <=: + // ./in.cue:10:11 + // #TimeSpan.duration: non-concrete value float in operand to -: + // ./in.cue:7:12 + // ./in.cue:4:12 + } + end: (_|_){ + // [incomplete] #TimeSpan.start: non-concrete value end for bound <=: + // ./in.cue:10:11 + // #TimeSpan.start: non-concrete value float in operand to -: + // ./in.cue:6:12 + // ./in.cue:4:12 + // #TimeSpan.duration: non-concrete value float in operand to -: + // ./in.cue:7:12 + // ./in.cue:4:12 + } + } + examples: (struct){ + eg1: (#struct){ + start: (float){ 10.0 } + duration: (float){ 2.1 } + end: (float){ 12.1 } + } + eg2: (#struct){ + start: (_|_){ + // [incomplete] examples.eg2.start: non-concrete value end for bound <=: + // ./in.cue:10:11 + // examples.eg2.duration: non-concrete value float in operand to -: + // ./in.cue:7:12 + // ./in.cue:4:12 + } + duration: (_|_){ + // [incomplete] examples.eg2.start: non-concrete value end for bound <=: + // ./in.cue:10:11 + // examples.eg2.duration: non-concrete value float in operand to -: + // ./in.cue:7:12 + // ./in.cue:4:12 + } + end: (_|_){ + // [incomplete] examples.eg2.start: non-concrete value end for bound <=: + // ./in.cue:10:11 + // examples.eg2.duration: non-concrete value float in operand to -: + // ./in.cue:7:12 + // ./in.cue:4:12 + } + } + eg3: (#struct){ + end: (_|_){ + // [incomplete] examples.eg3.duration: non-concrete value <=10.0 & float in operand to -: + // ./in.cue:7:12 + // ./in.cue:10:9 + } + start: (_|_){ + // [incomplete] examples.eg3.duration: non-concrete value <=10.0 & float in operand to -: + // ./in.cue:7:12 + // ./in.cue:10:9 + } + duration: (_|_){ + // [incomplete] examples.eg3.duration: non-concrete value <=10.0 & float in operand to -: + // ./in.cue:7:12 + // ./in.cue:10:9 + } + } + } +} +-- diff/explanation -- +the new evaluator includes positions with the cycle error and the old evaluator does not. +-- diff/-out/evalalpha<==>+out/eval -- +diff old new +--- old ++++ new +@@ -1,15 +1,31 @@ + (struct){ + #TimeSpan: (#struct){ + start: (_|_){ +- // [cycle] cycle error ++ // [incomplete] #TimeSpan.start: non-concrete value end for bound <=: ++ // ./in.cue:10:11 ++ // #TimeSpan.start: non-concrete value float in operand to -: ++ // ./in.cue:6:12 ++ // ./in.cue:4:12 ++ // #TimeSpan.duration: non-concrete value float in operand to -: ++ // ./in.cue:7:12 ++ // ./in.cue:4:12 + } + duration: (_|_){ +- // [cycle] cycle error: +- // ./in.cue:7:12 ++ // [incomplete] #TimeSpan.start: non-concrete value end for bound <=: ++ // ./in.cue:10:11 ++ // #TimeSpan.duration: non-concrete value float in operand to -: ++ // ./in.cue:7:12 ++ // ./in.cue:4:12 + } + end: (_|_){ +- // [cycle] cycle error: +- // ./in.cue:8:12 ++ // [incomplete] #TimeSpan.start: non-concrete value end for bound <=: ++ // ./in.cue:10:11 ++ // #TimeSpan.start: non-concrete value float in operand to -: ++ // ./in.cue:6:12 ++ // ./in.cue:4:12 ++ // #TimeSpan.duration: non-concrete value float in operand to -: ++ // ./in.cue:7:12 ++ // ./in.cue:4:12 + } + } + examples: (struct){ +@@ -20,26 +36,42 @@ + } + eg2: (#struct){ + start: (_|_){ +- // [cycle] cycle error +- } +- duration: (_|_){ +- // [cycle] cycle error: +- // ./in.cue:7:12 +- } +- end: (_|_){ +- // [cycle] cycle error ++ // [incomplete] examples.eg2.start: non-concrete value end for bound <=: ++ // ./in.cue:10:11 ++ // examples.eg2.duration: non-concrete value float in operand to -: ++ // ./in.cue:7:12 ++ // ./in.cue:4:12 ++ } ++ duration: (_|_){ ++ // [incomplete] examples.eg2.start: non-concrete value end for bound <=: ++ // ./in.cue:10:11 ++ // examples.eg2.duration: non-concrete value float in operand to -: ++ // ./in.cue:7:12 ++ // ./in.cue:4:12 ++ } ++ end: (_|_){ ++ // [incomplete] examples.eg2.start: non-concrete value end for bound <=: ++ // ./in.cue:10:11 ++ // examples.eg2.duration: non-concrete value float in operand to -: ++ // ./in.cue:7:12 ++ // ./in.cue:4:12 + } + } + eg3: (#struct){ + end: (_|_){ +- // [cycle] cycle error: +- // ./in.cue:8:12 +- } +- start: (_|_){ +- // [cycle] cycle error +- } +- duration: (_|_){ +- // [cycle] cycle error ++ // [incomplete] examples.eg3.duration: non-concrete value <=10.0 & float in operand to -: ++ // ./in.cue:7:12 ++ // ./in.cue:10:9 ++ } ++ start: (_|_){ ++ // [incomplete] examples.eg3.duration: non-concrete value <=10.0 & float in operand to -: ++ // ./in.cue:7:12 ++ // ./in.cue:10:9 ++ } ++ duration: (_|_){ ++ // [incomplete] examples.eg3.duration: non-concrete value <=10.0 & float in operand to -: ++ // ./in.cue:7:12 ++ // ./in.cue:10:9 + } + } + } +-- out/eval -- +(struct){ + #TimeSpan: (#struct){ + start: (_|_){ + // [cycle] cycle error + } + duration: (_|_){ + // [cycle] cycle error: + // ./in.cue:7:12 + } + end: (_|_){ + // [cycle] cycle error: + // ./in.cue:8:12 + } + } + examples: (struct){ + eg1: (#struct){ + start: (float){ 10.0 } + duration: (float){ 2.1 } + end: (float){ 12.1 } + } + eg2: (#struct){ + start: (_|_){ + // [cycle] cycle error + } + duration: (_|_){ + // [cycle] cycle error: + // ./in.cue:7:12 + } + end: (_|_){ + // [cycle] cycle error + } + } + eg3: (#struct){ + end: (_|_){ + // [cycle] cycle error: + // ./in.cue:8:12 + } + start: (_|_){ + // [cycle] cycle error + } + duration: (_|_){ + // [cycle] cycle error + } + } + } +} +-- out/compile -- +--- in.cue +{ + #TimeSpan: { + start: float + duration: float + end: float + start: (〈0;end〉 - 〈0;duration〉) + duration: (〈0;end〉 - 〈0;start〉) + end: (〈0;start〉 + 〈0;duration〉) + start: <=〈0;end〉 + } + examples: { + [string]: 〈1;#TimeSpan〉 + } + examples: { + eg1: { + start: 10.0 + duration: 2.1 + } + } + examples: { + eg2: { + start: 10.0 + } + } + examples: { + eg3: { + end: 10.0 + } + } +}