Skip to content

Commit

Permalink
internal/core/adt: fix missing dereference for equal
Browse files Browse the repository at this point in the history
Now we have structure sharing, we need to ensure that
Vertex values are dereferenced properly.

Issue #3060
Issue #2884
Issue #2854

Signed-off-by: Marcel van Lohuizen <[email protected]>
Change-Id: Ied35aa7f7f08205bbdb54415d78e78f1b83c8b62
Reviewed-on: https://review.gerrithub.io/c/cue-lang/cue/+/1194081
Unity-Result: CUE porcuepine <[email protected]>
Reviewed-by: Daniel Martí <[email protected]>
TryBot-Result: CUEcueckoo <[email protected]>
  • Loading branch information
mpvl committed Apr 30, 2024
1 parent 6e48c0d commit bc3e24c
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
2 changes: 0 additions & 2 deletions cue/types_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2345,8 +2345,6 @@ func TestEquals(t *testing.T) {
}}
for _, tc := range testCases {
runMatrix(t, "", func(t *testing.T, cfg *evalConfig) {
TODO_Sharing(t, cfg)

r := cfg.runtime()

a, err := r.Compile("a", tc.a)
Expand Down
18 changes: 15 additions & 3 deletions internal/core/adt/equality.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,24 @@ func equalVertex(ctx *OpContext, x *Vertex, v Value, flags Flag) bool {
if !ok {
return false
}
if x == y {
return true
}

// Note that the arc type of an originating node may be different than
// the one we are sharing. So do this check before dereferencing.
// For instance:
//
// a?: #B // ArcOptional
// #B: {} // ArcMember
if x.ArcType != y.ArcType {
return false
}

x = x.Indirect()
y = y.Indirect()

if x == y {
return true
}

xk := x.Kind()
yk := y.Kind()

Expand Down

0 comments on commit bc3e24c

Please sign in to comment.