Skip to content

Commit

Permalink
pkg/list: fix list.Unique dedupping
Browse files Browse the repository at this point in the history
Fixes #797

Change-Id: Iae45ae627d6283027179509aab9546f67fc387be
Reviewed-on: https://cue-review.googlesource.com/c/cue/+/8904
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 70e2f2e commit af3c9dc
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
2 changes: 1 addition & 1 deletion pkg/list/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ func MaxItems(a []cue.Value, n int) bool {
func UniqueItems(a []cue.Value) bool {
b := []string{}
for _, v := range a {
b = append(b, fmt.Sprint(v))
b = append(b, fmt.Sprintf("%+v", v))
}
sort.Strings(b)
for i := 1; i < len(b); i++ {
Expand Down
19 changes: 19 additions & 0 deletions pkg/list/testdata/list.txtar
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,16 @@ concat: {
t7: x: 1
t8: x: [1, [2]]
}
unique: {
issue797: {
mylst: [
{ foo: "bar" },
{ foo: "baz" }
]

_testmylst: list.UniqueItems & [for x in mylst { x.foo } ]
}
}
-- out/list --
Errors:
error in call to list.Concat: cannot use value 1 (type int) as list
Expand Down Expand Up @@ -115,4 +125,13 @@ concat: {
v: _|_ // error in call to list.Concat: cannot use value 1 (type int) as list (and 1 more errors)
}
}
unique: {
issue797: {
mylst: [{
foo: "bar"
}, {
foo: "baz"
}]
}
}

0 comments on commit af3c9dc

Please sign in to comment.