Skip to content

Commit

Permalink
internal/core/adt: also check closedness for list in Equal
Browse files Browse the repository at this point in the history
Without this check, open lists will be considered to be
identical to closed lists. This, in turn, could lead to one
of such cases to be eliminated from a disjunction.

E.g. closed([]) | [] should not be simplified to closed([]).

Issue #2884

Signed-off-by: Marcel van Lohuizen <mpvl@gmail.com>
Change-Id: I3e410c651729d0883809c83d20a980794d278e5f
Reviewed-on: https://review.gerrithub.io/c/cue-lang/cue/+/1191574
Reviewed-by: Daniel Martí <mvdan@mvdan.cc>
TryBot-Result: CUEcueckoo <cueckoo@cuelang.org>
Unity-Result: CUE porcuepine <cue.porcuepine@gmail.com>
  • Loading branch information
mpvl committed Apr 12, 2024
1 parent 8e58091 commit 30c5f27
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 76 deletions.
36 changes: 0 additions & 36 deletions cue/testdata/comprehensions/issue507.txtar
Expand Up @@ -33,42 +33,6 @@ Retain: 0
Unifications: 11
Conjuncts: 17
Disjuncts: 15
-- out/evalalpha --
(struct){
somelist: (list){
}
foo: (#list){
}
otherlist: (#list){
0: (string){ "something" }
}
z: (#list){
0: (string){ "hello z: something" }
}
extlist: (list){ |(*(#list){
0: (string){ "something" }
}, (list){
}) }
bar: (#list){
0: (string){ "hello bar: something" }
}
}
-- diff/-out/evalalpha<==>+out/eval --
diff old new
--- old
+++ new
@@ -1,7 +1,6 @@
(struct){
- somelist: (list){ |(*(#list){
- }, (list){
- }) }
+ somelist: (list){
+ }
foo: (#list){
}
otherlist: (#list){
-- diff/todo/p0 --
somelist: Dropped disjunction
-- out/eval --
(struct){
somelist: (list){ |(*(#list){
Expand Down
40 changes: 0 additions & 40 deletions cue/testdata/fulleval/027_len_of_incomplete_types.txtar
Expand Up @@ -42,46 +42,6 @@ Retain: 3
Unifications: 59
Conjuncts: 105
Disjuncts: 93
-- out/evalalpha --
(struct){
args: (#list){
}
v1: (int){ 0 }
v2: (int){ 0 }
v3: (int){ 0 }
v4: (int){ 1 }
v5: (_|_){
// [incomplete] v5: unresolved disjunction {a:3} | {a:4} (type struct):
// ./in.cue:6:7
}
v6: (_|_){
// [incomplete] v6: unresolved disjunction 'sf' | 'dd' (type bytes):
// ./in.cue:7:7
}
v7: (int){ 2 }
v8: (_|_){
// [incomplete] v8: unresolved disjunction [2] | [1,2] (type list):
// ./in.cue:9:7
}
v9: (int){ 4 }
v10: (int){ 0 }
}
-- diff/-out/evalalpha<==>+out/eval --
diff old new
--- old
+++ new
@@ -1,7 +1,6 @@
(struct){
- args: (list){ |(*(#list){
- }, (list){
- }) }
+ args: (#list){
+ }
v1: (int){ 0 }
v2: (int){ 0 }
v3: (int){ 0 }
-- diff/todo/p0 --
Incorrectly chosen default.
-- out/eval --
(struct){
args: (list){ |(*(#list){
Expand Down
3 changes: 3 additions & 0 deletions internal/core/adt/equality.go
Expand Up @@ -67,6 +67,9 @@ func equalVertex(ctx *OpContext, x *Vertex, v Value, flags Flag) bool {
if x.IsClosedStruct() != y.IsClosedStruct() {
return false
}
if x.IsClosedList() != y.IsClosedList() {
return false
}
if !equalClosed(ctx, x, y, flags) {
return false
}
Expand Down

0 comments on commit 30c5f27

Please sign in to comment.