pkg/list: fix list.Unique dedupping
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>
diff --git a/pkg/list/list.go b/pkg/list/list.go
index dadc398..3f86e1d 100644
--- a/pkg/list/list.go
+++ b/pkg/list/list.go
@@ -231,7 +231,7 @@
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++ {
diff --git a/pkg/list/testdata/list.txtar b/pkg/list/testdata/list.txtar
index 6291774..05f94e4 100644
--- a/pkg/list/testdata/list.txtar
+++ b/pkg/list/testdata/list.txtar
@@ -31,6 +31,16 @@
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
@@ -115,4 +125,13 @@
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"
+ }]
+ }
+}