Skip to content

Commit e8e8682

Browse files
committed
internal/core/adt: limit closedness check in Equal
The closedness check only makes sense for CheckStructural . The flags != 0 test was used before some of the other options were introduced. We now only check closedness if CheckStructural is enabled. Note that this currently only impacts evalv2 behavior. The resulting changes are correct. Issue #2583 Signed-off-by: Marcel van Lohuizen <[email protected]> Change-Id: I32a188f2d092469f043f6ae047cf914ffef90708 Reviewed-on: https://review.gerrithub.io/c/cue-lang/cue/+/1217007 Unity-Result: CUE porcuepine <[email protected]> TryBot-Result: CUEcueckoo <[email protected]> Reviewed-by: Roger Peppe <[email protected]>
1 parent 26e1596 commit e8e8682

File tree

2 files changed

+14
-41
lines changed

2 files changed

+14
-41
lines changed

internal/core/adt/equality.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ func equalVertex(ctx *OpContext, x *Vertex, v Value, flags Flag) bool {
7979
}
8080

8181
// TODO: this really should be subsumption.
82-
if flags != 0 {
82+
if flags&CheckStructural != 0 {
8383
if x.IsClosedStruct() != y.IsClosedStruct() {
8484
return false
8585
}

pkg/list/testdata/unique.txtar

Lines changed: 13 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -196,17 +196,16 @@ fail: {
196196
diff old new
197197
--- old
198198
+++ new
199-
@@ -2,6 +2,9 @@
199+
@@ -2,7 +2,7 @@
200200
fail.ignoreHidden: invalid value [1,1] (does not satisfy list.UniqueItems): equal value (1) at position 0 and 1:
201201
./in.cue:3:21
202202
./in.cue:48:16
203+
-fail.ignoreOptError: invalid value [{a:1},{a:1,b?:_|_(fail.ignoreOptError.1.b: conflicting values int and string (mismatched types int and string))}] (does not satisfy list.UniqueItems): equal values at position 0 and 1:
203204
+fail.ignoreOptError: invalid value [~(#a),~(#abErr)] (does not satisfy list.UniqueItems): equal values at position 0 and 1:
204-
+ ./in.cue:3:21
205-
+ ./in.cue:52:18
206-
fail.ints: invalid value [1,2,1] (does not satisfy list.UniqueItems): equal value (1) at position 0 and 2:
207205
./in.cue:3:21
208-
./in.cue:44:8
209-
@@ -8,7 +11,7 @@
206+
./in.cue:52:18
207+
fail.ints: invalid value [1,2,1] (does not satisfy list.UniqueItems): equal value (1) at position 0 and 2:
208+
@@ -11,7 +11,7 @@
210209
fail.structOrderIrrelevant: invalid value [{b:1,a:0},{a:0,b:1}] (does not satisfy list.UniqueItems): equal values at position 0 and 1:
211210
./in.cue:3:21
212211
./in.cue:72:30
@@ -215,21 +214,7 @@ diff old new
215214
./in.cue:3:21
216215
./in.cue:45:11
217216

218-
@@ -67,12 +70,7 @@
219-
}]
220-
221-
// Ditto. This time with actually closed fields.
222-
- withOptional3: [{
223-
- a: 1
224-
- }, {
225-
- a: 1
226-
- b?: int
227-
- }]
228-
+ withOptional3: list.UniqueItems() & [#a, #ab]
229-
230-
// Ditto. There are not optional fields, but the structs are open.
231-
openSpecific: list.UniqueItems() & [{
232-
@@ -100,7 +98,7 @@
217+
@@ -98,7 +98,7 @@
233218
}
234219
fail: {
235220
ints: _|_ // fail.ints: invalid value [1,2,1] (does not satisfy list.UniqueItems): equal value (1) at position 0 and 2
@@ -238,16 +223,11 @@ diff old new
238223

239224
// Hidden values do not play a role in the comparisson.
240225
ignoreHidden: _|_ // fail.ignoreHidden: invalid value [1,1] (does not satisfy list.UniqueItems): equal value (1) at position 0 and 1
241-
@@ -107,12 +105,7 @@
226+
@@ -105,7 +105,7 @@
242227

243228
// This can be a permanent error, as the optional field of the second
244229
// element is erroneous an cannot match.
245-
- ignoreOptError: [{
246-
- a: 1
247-
- }, {
248-
- a: 1
249-
- b?: int & string
250-
- }]
230+
- ignoreOptError: _|_ // fail.ignoreOptError: invalid value [{a:1},{a:1,b?:_|_(fail.ignoreOptError.1.b: conflicting values int and string (mismatched types int and string))}] (does not satisfy list.UniqueItems): equal values at position 0 and 1
251231
+ ignoreOptError: _|_ // fail.ignoreOptError: invalid value [~(#a),~(#abErr)] (does not satisfy list.UniqueItems): equal values at position 0 and 1
252232

253233
// Struct field order is irrelevant. We simulate finalising
@@ -257,6 +237,9 @@ Errors:
257237
fail.ignoreHidden: invalid value [1,1] (does not satisfy list.UniqueItems): equal value (1) at position 0 and 1:
258238
./in.cue:3:21
259239
./in.cue:48:16
240+
fail.ignoreOptError: invalid value [{a:1},{a:1,b?:_|_(fail.ignoreOptError.1.b: conflicting values int and string (mismatched types int and string))}] (does not satisfy list.UniqueItems): equal values at position 0 and 1:
241+
./in.cue:3:21
242+
./in.cue:52:18
260243
fail.ints: invalid value [1,2,1] (does not satisfy list.UniqueItems): equal value (1) at position 0 and 2:
261244
./in.cue:3:21
262245
./in.cue:44:8
@@ -322,12 +305,7 @@ incomplete: {
322305
}]
323306

324307
// Ditto. This time with actually closed fields.
325-
withOptional3: [{
326-
a: 1
327-
}, {
328-
a: 1
329-
b?: int
330-
}]
308+
withOptional3: list.UniqueItems() & [#a, #ab]
331309

332310
// Ditto. There are not optional fields, but the structs are open.
333311
openSpecific: list.UniqueItems() & [{
@@ -362,12 +340,7 @@ fail: {
362340

363341
// This can be a permanent error, as the optional field of the second
364342
// element is erroneous an cannot match.
365-
ignoreOptError: [{
366-
a: 1
367-
}, {
368-
a: 1
369-
b?: int & string
370-
}]
343+
ignoreOptError: _|_ // fail.ignoreOptError: invalid value [{a:1},{a:1,b?:_|_(fail.ignoreOptError.1.b: conflicting values int and string (mismatched types int and string))}] (does not satisfy list.UniqueItems): equal values at position 0 and 1
371344

372345
// Struct field order is irrelevant. We simulate finalising
373346
// these values here via close(), which gives the same behaviour

0 commit comments

Comments
 (0)