From 4900cfc6511464d706c1f5f520c1a87b7dc6dca7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Mart=C3=AD?= Date: Tue, 21 May 2024 12:45:22 +0100 Subject: [PATCH] cue: add a regression test for a disjunction bug fixed in evalv3 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit As can be seen in the diff, the old evaluator resulted in the fields: h: a: v: *"a" | "b" | "c" h: b: v: *"a" | "b" | "c" h: c: v: *"a" | *"b" | *"c" Which, when exporting, would understandably result in an error: h.c.v: incomplete value "a" | "b" | "c" The new evaluator correctly keeps "a" as the only default in all fields: h: a: v: *"a" | "b" | "c" h: b: v: *"a" | "b" | "c" h: c: v: *"a" | "b" | "c" Closes #770. Signed-off-by: Daniel Martí Change-Id: Id3e5e9c522307900331dc0fa29b936f773750497 Reviewed-on: https://review.gerrithub.io/c/cue-lang/cue/+/1195003 Reviewed-by: Paul Jolly TryBot-Result: CUEcueckoo --- cue/testdata/disjunctions/elimination.txtar | 126 +++++++++++++++++++- 1 file changed, 121 insertions(+), 5 deletions(-) diff --git a/cue/testdata/disjunctions/elimination.txtar b/cue/testdata/disjunctions/elimination.txtar index ef625144f89..2453a416c7f 100644 --- a/cue/testdata/disjunctions/elimination.txtar +++ b/cue/testdata/disjunctions/elimination.txtar @@ -505,6 +505,26 @@ issue3149: { {name: "an exception"}, ] } +-- issue770.cue -- +issue770: { + #A: { + v: "a" | "b" | "c" + } + h: [string]: #A + h: a: { + v: *"a" | string + } + h: [=~"^b"]: { + v: *h.a.v | string + } + h: [=~"^c"]: { + v: *h.b.v | string + } + h: b: _ + h: boo: _ + h: c: _ + h: coo: _ +} -- out/evalalpha -- (struct){ disambiguateClosed: (struct){ @@ -1441,6 +1461,28 @@ issue3149: { } } } + issue770: (struct){ + #A: (#struct){ + v: (string){ |((string){ "a" }, (string){ "b" }, (string){ "c" }) } + } + h: (struct){ + a: (#struct){ + v: (string){ |(*(string){ "a" }, (string){ "b" }, (string){ "c" }) } + } + b: (#struct){ + v: (string){ |(*(string){ "a" }, (string){ "b" }, (string){ "c" }) } + } + boo: (#struct){ + v: (string){ |(*(string){ "a" }, (string){ "b" }, (string){ "c" }) } + } + c: (#struct){ + v: (string){ |(*(string){ "a" }, (string){ "b" }, (string){ "c" }) } + } + coo: (#struct){ + v: (string){ |(*(string){ "a" }, (string){ "b" }, (string){ "c" }) } + } + } + } } -- diff/-out/evalalpha<==>+out/eval -- diff old new @@ -2279,16 +2321,29 @@ diff old new } } } +@@ -1078,10 +948,10 @@ + v: (string){ |(*(string){ "a" }, (string){ "b" }, (string){ "c" }) } + } + c: (#struct){ +- v: (string){ |(*(string){ "a" }, *(string){ "b" }, *(string){ "c" }) } ++ v: (string){ |(*(string){ "a" }, (string){ "b" }, (string){ "c" }) } + } + coo: (#struct){ +- v: (string){ |(*(string){ "a" }, *(string){ "b" }, *(string){ "c" }) } ++ v: (string){ |(*(string){ "a" }, (string){ "b" }, (string){ "c" }) } + } + } + } -- out/eval/stats -- Leaks: 4 -Freed: 2403 -Reused: 2387 +Freed: 2554 +Reused: 2538 Allocs: 20 Retain: 115 -Unifications: 1278 -Conjuncts: 3512 -Disjuncts: 2518 +Unifications: 1292 +Conjuncts: 3726 +Disjuncts: 2669 -- diff/todo/p1 -- issue2263.full: missing elimination, may be lack of closeContext -- diff/todo/p2 -- @@ -2302,6 +2357,7 @@ issue2209.simplified.t3: new evaluator fixes known bug. preserveClosedness.medium.p*: discarding of default is correct. issue1417: new evaluator fixes known bug issue3149: new evaluator fixes known bug +issue770: new evaluator fixes a bug in "c" and "coo" where defaults did not apply correctly. -- out/eval -- Errors: issue1417.ids.2: 2 errors in empty disjunction: @@ -3368,6 +3424,28 @@ Result: } } } + issue770: (struct){ + #A: (#struct){ + v: (string){ |((string){ "a" }, (string){ "b" }, (string){ "c" }) } + } + h: (struct){ + a: (#struct){ + v: (string){ |(*(string){ "a" }, (string){ "b" }, (string){ "c" }) } + } + b: (#struct){ + v: (string){ |(*(string){ "a" }, (string){ "b" }, (string){ "c" }) } + } + boo: (#struct){ + v: (string){ |(*(string){ "a" }, (string){ "b" }, (string){ "c" }) } + } + c: (#struct){ + v: (string){ |(*(string){ "a" }, *(string){ "b" }, *(string){ "c" }) } + } + coo: (#struct){ + v: (string){ |(*(string){ "a" }, *(string){ "b" }, *(string){ "c" }) } + } + } + } } -- out/compile -- --- in.cue @@ -4432,3 +4510,41 @@ Result: ] } } +--- issue770.cue +{ + issue770: { + #A: { + v: ("a"|"b"|"c") + } + h: { + [string]: 〈1;#A〉 + } + h: { + a: { + v: (*"a"|string) + } + } + h: { + [=~"^b"]: { + v: (*〈2;h〉.a.v|string) + } + } + h: { + [=~"^c"]: { + v: (*〈2;h〉.b.v|string) + } + } + h: { + b: _ + } + h: { + boo: _ + } + h: { + c: _ + } + h: { + coo: _ + } + } +}