Skip to content
This repository has been archived by the owner on Nov 18, 2021. It is now read-only.

Commit

Permalink
cue: Value.Equal should not only consider values
Browse files Browse the repository at this point in the history
It is verified that this is the same behavior as v0.2.2.
So this brings v0.3 closer to v0.2.

This also fixes builtins that still relied on the old
behavior.

Fixes #784

Change-Id: I80714da319f91bc09d2d6c3495deaa369d80c9d6
Reviewed-on: https://cue-review.googlesource.com/c/cue/+/8901
Reviewed-by: CUE cueckoo <cueckoo@gmail.com>
Reviewed-by: Marcel van Lohuizen <mpvl@golang.org>
  • Loading branch information
mpvl committed Mar 5, 2021
1 parent 91abe0d commit 7326cfa
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 6 deletions.
2 changes: 1 addition & 1 deletion cue/types.go
Expand Up @@ -1831,7 +1831,7 @@ func (v Value) Equals(other Value) bool {
if v.v == nil || other.v == nil {
return false
}
return adt.Equal(v.ctx().opCtx, v.v, other.v, adt.CheckStructural)
return adt.Equal(v.ctx().opCtx, v.v, other.v, 0)
}

// Format prints a debug version of a value.
Expand Down
15 changes: 15 additions & 0 deletions cue/types_test.go
Expand Up @@ -1493,6 +1493,21 @@ func TestEquals(t *testing.T) {
a: "foo",
}`,
false,
}, {
// Ignore closedness
`{ #Foo: { k: 1 }, a: #Foo }`,
`{ #Foo: { k: 1 }, a: { k: 1 } }`,
true,
}, {
// Ignore optional fields
`{ #Foo: { k: 1 }, a: #Foo }`,
`{ #Foo: { k: 1 }, a: { #Foo, i?: 1 } }`,
true,
}, {
// Treat embedding as equal
`{ a: 2, b: { 3 } }`,
`{ a: { 2 }, b: 3 }`,
true,
}}
for _, tc := range testCases {
t.Run("", func(t *testing.T) {
Expand Down
12 changes: 7 additions & 5 deletions internal/core/adt/equality.go
Expand Up @@ -57,11 +57,13 @@ func equalVertex(ctx *OpContext, x *Vertex, v Value, flags Flag) bool {
}

// TODO: this really should be subsumption.
if x.IsClosed(ctx) != y.IsClosed(ctx) {
return false
}
if flags != 0 && !equalClosed(ctx, x, y, flags) {
return false
if flags != 0 {
if x.IsClosed(ctx) != y.IsClosed(ctx) {
return false
}
if !equalClosed(ctx, x, y, flags) {
return false
}
}

loop1:
Expand Down

0 comments on commit 7326cfa

Please sign in to comment.