internal/core/eval: fix bug with nested embeded comprehensions
Fixes #556
Change-Id: I69a8fc2e7c321a86072df75df980000756ce78cd
Reviewed-on: https://cue-review.googlesource.com/c/cue/+/7462
Reviewed-by: CUE cueckoo <cueckoo@gmail.com>
Reviewed-by: Marcel van Lohuizen <mpvl@golang.org>
diff --git a/cue/testdata/comprehensions/nestembed.txtar b/cue/testdata/comprehensions/nestembed.txtar
new file mode 100644
index 0000000..baa9c3f
--- /dev/null
+++ b/cue/testdata/comprehensions/nestembed.txtar
@@ -0,0 +1,77 @@
+Issue #556
+
+-- in.cue --
+import "list"
+
+DeleteThis: ["this", "that"]
+useful_infra: {
+ gcp: cluters: 10
+ aws: clusters: 20
+ this: clusters: 1
+ that: clusters: 2
+}
+New_infra: {
+ for k,v in useful_infra {
+ if !list.Contains(DeleteThis, k) {
+ "\(k)": v
+ }
+ }
+}
+-- out/eval --
+(struct){
+ DeleteThis: (#list){
+ 0: (string){ "this" }
+ 1: (string){ "that" }
+ }
+ useful_infra: (struct){
+ gcp: (struct){
+ cluters: (int){ 10 }
+ }
+ aws: (struct){
+ clusters: (int){ 20 }
+ }
+ this: (struct){
+ clusters: (int){ 1 }
+ }
+ that: (struct){
+ clusters: (int){ 2 }
+ }
+ }
+ New_infra: (struct){
+ gcp: (struct){
+ cluters: (int){ 10 }
+ }
+ aws: (struct){
+ clusters: (int){ 20 }
+ }
+ }
+}
+-- out/compile --
+--- in.cue
+{
+ DeleteThis: [
+ "this",
+ "that",
+ ]
+ useful_infra: {
+ gcp: {
+ cluters: 10
+ }
+ aws: {
+ clusters: 20
+ }
+ this: {
+ clusters: 1
+ }
+ that: {
+ clusters: 2
+ }
+ }
+ New_infra: {
+ for k, v in 〈1;useful_infra〉 {
+ if !〈import;list〉.Contains(〈3;DeleteThis〉, 〈1;k〉) {
+ "\(〈2;k〉)": 〈2;v〉
+ }
+ }
+ }
+}
diff --git a/internal/core/eval/eval.go b/internal/core/eval/eval.go
index 60865c7..ec45c9b 100644
--- a/internal/core/eval/eval.go
+++ b/internal/core/eval/eval.go
@@ -1793,8 +1793,11 @@
}
}
+ progress = k < len(*all)
+
*all = (*all)[:k]
- return k < len(*all)
+
+ return progress
}
// addLists