Skip to content

Commit

Permalink
cue: add a regression test for a disjunction bug fixed in evalv3
Browse files Browse the repository at this point in the history
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í <mvdan@mvdan.cc>
Change-Id: Id3e5e9c522307900331dc0fa29b936f773750497
Reviewed-on: https://review.gerrithub.io/c/cue-lang/cue/+/1195003
Reviewed-by: Paul Jolly <paul@myitcv.io>
TryBot-Result: CUEcueckoo <cueckoo@cuelang.org>
  • Loading branch information
mvdan committed May 21, 2024
1 parent 7d49080 commit 4900cfc
Showing 1 changed file with 121 additions and 5 deletions.
126 changes: 121 additions & 5 deletions cue/testdata/disjunctions/elimination.txtar
Original file line number Diff line number Diff line change
Expand Up @@ -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){
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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 --
Expand All @@ -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:
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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: _
}
}
}

0 comments on commit 4900cfc

Please sign in to comment.