-- in.cue --
import "list"

// The following just chains existing fields and should NOT trigger a cycle
// detection error.


chain: t1: {
	#maxiter: 2

	// Trigger lookup of a.x0 before the "regular" evaluation of a.
	x: a.x0

	a: {
		for k, _ in [0, 1] {
			"x\(k)": (#DepthF & {#in: a["x\(k+1)"]}).#out
		}
	}

	a: x2: null


	#DepthF: {
		#in: _
		#out: {}
	}
}

chain: t2: p1: {
	X: 1

	// Reference X through x.x0 before X is inserted.
	for v in list.Concat([[0, X], []]) {
		x: "x\(v)": {}
	}

	x: _

	x.x0
}

chain: t2: p2: {
	// Reference X through x.x0 before X is inserted.
	for v in list.Concat([[0, X], []]) {
		x: "x\(v)": {}
	}

	x: _

	x.x0

	X: 1
}

chain: t3: p1: {
	X: 1

	for v in list.Range(0, X, 1) {
		x: "x\(v)": {}
	}

	x: _

	x.x0
}

chain: t3: p1: {
	for v in list.Range(0, X, 1) {
		x: "x\(v)": {}
	}

	x: _

	x.x0

	X: 1
}

-- issue2052.cue --
import (
	"list"
	"math"
)
issue2052: reduced: t1: {
	A: a: _
	Depth: {
		#maxiter: 1
		if math.Abs(#maxiter) == 1 {
			funcs: "\(0)": A
		}
		funcs: {}
		funcs["0"]
	}
}
issue2052: reduced: t2: {
	A: a: _
	Depth: {
		maxiter: 1
		for k, v in list.Range(0, maxiter, 1) {
			funcs: "\(0)": A
		}
		funcs: {}
		funcs["0"]
	}
}
issue2052: medium: t1: {
	#Depth: {
		#maxiter: 4

		for k, v in list.Range(0, #maxiter, 1) {
			#funcs: "\(k)": (#DepthF & {#next: #funcs["\(k+1)"]}).#func
		}

		#funcs: "\(#maxiter)": null

		#funcs["0"]
	}

	#DepthF: {
		#next: _
		#func: {
			#in:    _
			#basic: string | null
			out: {
				if (#in & #basic) != _|_ {1}
				if (#in & #basic) == _|_ {
					list.Max([for k, v in #in {(#next & {#in: v}).out}]) + 1
				}
			}
		}
	}

	tree: "bar"

	d: #Depth & {#in: tree}

}

issue2052: medium: t2: {
	#Depth: {
		#maxiter: 4

		for k, v in list.Range(0, #maxiter, 1) {
			#funcs: "\(k)": (#DepthF & {#next: #funcs["\(k+1)"]}).#func
		}

		#funcs:{
			for k, v in list.Range(0, #maxiter, 1) {
				 "\(k)": (#DepthF & {#next: #funcs["\(k+1)"]}).#func
			}
		}

		#funcs: "\(#maxiter)": null

		#funcs["0"]
	}

	#DepthF: {
		#next: _
		#func: {
			#in:    _
			#basic: string | null
			out: {
				if (#in & #basic) != _|_ {1}
				if (#in & #basic) == _|_ {
					list.Max([for k, v in #in {(#next & {#in: v}).out}]) + 1
				}
			}
		}
	}

	tree: "bar"

	d: #Depth & {#in: tree}
}

issue2052: full: {
	#RecurseN: {
		// this is the bound on our recursion
		#maxiter: uint | *4

		// This is the function list element
		// we generate this to simulate recursion
		#funcFactory: {
			#next: _
			#func: _
		}

		// this is our "recursion unrolling"
		for k, v in list.Range(0, #maxiter, 1) {
			// this is where we build up our indexed functions and the references between them
			#funcs: "\(k)": (#funcFactory & {#next: #funcs["\(k+1)"]}).#func
		}

		// our final value needs to be null
		#funcs: "\(#maxiter)": null

		// we embed the head of the list so that the values
		// we write this into can be used like other CUE "functions"
		#funcs["0"]
	}

	#DepthF: {
		#next: _
		#func: {
			#in:    _
			#basic: int | number | string | bytes | null
			out: {
				// if we have a basic type, we are at a leaf, depth is 1
				if (#in & #basic) != _|_ {1}

				// if we are not a basic type, then we are 1 + the max of children
				if (#in & #basic) == _|_ {
					// this is our "recursion" for each child
					let depths = [for k, v in #in {(#next & {#in: v}).out}]
					list.Max(depths) + 1
				}
			}
		}
	}

	#Depth: #RecurseN & {#maxiter: 11, #funcFactory: #DepthF}

	tree: {
		a: {
			foo: "bar"
			a: b: c: "d"
		}
		cow: "moo"
	}

	d: #Depth & {#in: tree}
}
-- out/evalalpha --
(struct){
  chain: (struct){
    t1: (struct){
      #maxiter: (int){ 2 }
      x: (#struct){
      }
      a: (struct){
        x2: (null){ null }
        x0: (#struct){
        }
        x1: (#struct){
        }
      }
      #DepthF: (#struct){
        #in: (_){ _ }
        #out: (#struct){
        }
      }
    }
    t2: (struct){
      p1: (struct){
        X: (int){ 1 }
        x: (struct){
          x0: (struct){
          }
          x1: (struct){
          }
        }
      }
      p2: (struct){
        x: (struct){
          x0: (struct){
          }
          x1: (struct){
          }
        }
        X: (int){ 1 }
      }
    }
    t3: (struct){
      p1: (struct){
        X: (int){ 1 }
        x: (struct){
          x0: (struct){
          }
        }
      }
    }
  }
  issue2052: (struct){
    reduced: (struct){
      t1: (struct){
        A: (struct){
          a: (_){ _ }
        }
        Depth: (struct){
          #maxiter: (int){ 1 }
          funcs: (struct){
            "0": ~(issue2052.reduced.t1.A)
          }
          a: (_){ _ }
        }
      }
      t2: (struct){
        A: (struct){
          a: (_){ _ }
        }
        Depth: (struct){
          maxiter: (int){ 1 }
          funcs: (struct){
            "0": ~(issue2052.reduced.t2.A)
          }
          a: (_){ _ }
        }
      }
    }
    medium: (struct){
      t1: (struct){
        #Depth: (#struct){
          #maxiter: (int){ 4 }
          #funcs: (#struct){
            "4": (null){ null }
            "0": (#struct){
              #in: (_){ _ }
              #basic: ((null|string)){ |((string){ string }, (null){ null }) }
              out: (int){ 1 }
            }
            "1": (#struct){
              #in: (_){ _ }
              #basic: ((null|string)){ |((string){ string }, (null){ null }) }
              out: (int){ 1 }
            }
            "2": (#struct){
              #in: (_){ _ }
              #basic: ((null|string)){ |((string){ string }, (null){ null }) }
              out: (int){ 1 }
            }
            "3": (#struct){
              #in: (_){ _ }
              #basic: ((null|string)){ |((string){ string }, (null){ null }) }
              out: (int){ 1 }
            }
          }
          #in: (_){ _ }
          #basic: ((null|string)){ |((string){ string }, (null){ null }) }
          out: (int){ 1 }
        }
        #DepthF: (#struct){
          #next: (_){ _ }
          #func: (#struct){
            #in: (_){ _ }
            #basic: ((null|string)){ |((string){ string }, (null){ null }) }
            out: (int){ 1 }
          }
        }
        tree: (string){ "bar" }
        d: (#struct){
          #in: (string){ "bar" }
          #maxiter: (int){ 4 }
          #funcs: (#struct){
            "4": (null){ null }
            "0": (#struct){
              #in: (_){ _ }
              #basic: ((null|string)){ |((string){ string }, (null){ null }) }
              out: (int){ 1 }
            }
            "1": (#struct){
              #in: (_){ _ }
              #basic: ((null|string)){ |((string){ string }, (null){ null }) }
              out: (int){ 1 }
            }
            "2": (#struct){
              #in: (_){ _ }
              #basic: ((null|string)){ |((string){ string }, (null){ null }) }
              out: (int){ 1 }
            }
            "3": (#struct){
              #in: (_){ _ }
              #basic: ((null|string)){ |((string){ string }, (null){ null }) }
              out: (int){ 1 }
            }
          }
          #basic: ((null|string)){ |((string){ string }, (null){ null }) }
          out: (int){ 1 }
        }
      }
      t2: (struct){
        #Depth: (#struct){
          #maxiter: (int){ 4 }
          #funcs: (#struct){
            "4": (null){ null }
            "0": (#struct){
              #in: (_){ _ }
              #basic: ((null|string)){ |((string){ string }, (null){ null }) }
              out: (int){ 1 }
            }
            "1": (#struct){
              #in: (_){ _ }
              #basic: ((null|string)){ |((string){ string }, (null){ null }) }
              out: (int){ 1 }
            }
            "2": (#struct){
              #in: (_){ _ }
              #basic: ((null|string)){ |((string){ string }, (null){ null }) }
              out: (int){ 1 }
            }
            "3": (#struct){
              #in: (_){ _ }
              #basic: ((null|string)){ |((string){ string }, (null){ null }) }
              out: (int){ 1 }
            }
          }
          #in: (_){ _ }
          #basic: ((null|string)){ |((string){ string }, (null){ null }) }
          out: (int){ 1 }
        }
        #DepthF: (#struct){
          #next: (_){ _ }
          #func: (#struct){
            #in: (_){ _ }
            #basic: ((null|string)){ |((string){ string }, (null){ null }) }
            out: (int){ 1 }
          }
        }
        tree: (string){ "bar" }
        d: (#struct){
          #in: (string){ "bar" }
          #maxiter: (int){ 4 }
          #funcs: (#struct){
            "4": (null){ null }
            "0": (#struct){
              #in: (_){ _ }
              #basic: ((null|string)){ |((string){ string }, (null){ null }) }
              out: (int){ 1 }
            }
            "1": (#struct){
              #in: (_){ _ }
              #basic: ((null|string)){ |((string){ string }, (null){ null }) }
              out: (int){ 1 }
            }
            "2": (#struct){
              #in: (_){ _ }
              #basic: ((null|string)){ |((string){ string }, (null){ null }) }
              out: (int){ 1 }
            }
            "3": (#struct){
              #in: (_){ _ }
              #basic: ((null|string)){ |((string){ string }, (null){ null }) }
              out: (int){ 1 }
            }
          }
          #basic: ((null|string)){ |((string){ string }, (null){ null }) }
          out: (int){ 1 }
        }
      }
    }
    full: (struct){
      #RecurseN: (_){
        _
        #maxiter: (int){ |(*(int){ 4 }, (int){ &(>=0, int) }) }
        #funcFactory: (#struct){
          #next: (_){ _ }
          #func: (_){ _ }
        }
        #funcs: (#struct){
          "4": (null){ null }
          "0": (_){ _ }
          "1": (_){ _ }
          "2": (_){ _ }
          "3": (_){ _ }
        }
      }
      #DepthF: (#struct){
        #next: (_){ _ }
        #func: (#struct){
          #in: (_){ _ }
          #basic: ((null|string|bytes|number)){ |((int){ int }, (number){ number }, (string){ string }, (bytes){ bytes }, (null){ null }) }
          out: (int){
            1
            let depths#1multi = [
              for k, v in 〈3;#in〉 {
                (〈6;#next〉 & {
                  #in: 〈2;v〉
                }).out
              },
            ]
          }
        }
      }
      #Depth: (#struct){
        #maxiter: (int){ 11 }
        #funcFactory: (#struct){
          #next: (_){ _ }
          #func: (#struct){
            #in: (_){ _ }
            #basic: ((null|string|bytes|number)){ |((int){ int }, (number){ number }, (string){ string }, (bytes){ bytes }, (null){ null }) }
            out: (int){
              1
              let depths#1multi = [
                for k, v in 〈3;#in〉 {
                  (〈6;#next〉 & {
                    #in: 〈2;v〉
                  }).out
                },
              ]
            }
          }
        }
        #funcs: (#struct){
          "11": (null){ null }
          "0": (#struct){
            #in: (_){ _ }
            #basic: ((null|string|bytes|number)){ |((int){ int }, (number){ number }, (string){ string }, (bytes){ bytes }, (null){ null }) }
            out: (int){
              1
              let depths#1multi = [
                for k, v in 〈3;#in〉 {
                  (〈6;#next〉 & {
                    #in: 〈2;v〉
                  }).out
                },
              ]
            }
          }
          "1": (#struct){
            #in: (_){ _ }
            #basic: ((null|string|bytes|number)){ |((int){ int }, (number){ number }, (string){ string }, (bytes){ bytes }, (null){ null }) }
            out: (int){
              1
              let depths#1multi = [
                for k, v in 〈3;#in〉 {
                  (〈6;#next〉 & {
                    #in: 〈2;v〉
                  }).out
                },
              ]
            }
          }
          "2": (#struct){
            #in: (_){ _ }
            #basic: ((null|string|bytes|number)){ |((int){ int }, (number){ number }, (string){ string }, (bytes){ bytes }, (null){ null }) }
            out: (int){
              1
              let depths#1multi = [
                for k, v in 〈3;#in〉 {
                  (〈6;#next〉 & {
                    #in: 〈2;v〉
                  }).out
                },
              ]
            }
          }
          "3": (#struct){
            #in: (_){ _ }
            #basic: ((null|string|bytes|number)){ |((int){ int }, (number){ number }, (string){ string }, (bytes){ bytes }, (null){ null }) }
            out: (int){
              1
              let depths#1multi = [
                for k, v in 〈3;#in〉 {
                  (〈6;#next〉 & {
                    #in: 〈2;v〉
                  }).out
                },
              ]
            }
          }
          "4": (#struct){
            #in: (_){ _ }
            #basic: ((null|string|bytes|number)){ |((int){ int }, (number){ number }, (string){ string }, (bytes){ bytes }, (null){ null }) }
            out: (int){
              1
              let depths#1multi = [
                for k, v in 〈3;#in〉 {
                  (〈6;#next〉 & {
                    #in: 〈2;v〉
                  }).out
                },
              ]
            }
          }
          "5": (#struct){
            #in: (_){ _ }
            #basic: ((null|string|bytes|number)){ |((int){ int }, (number){ number }, (string){ string }, (bytes){ bytes }, (null){ null }) }
            out: (int){
              1
              let depths#1multi = [
                for k, v in 〈3;#in〉 {
                  (〈6;#next〉 & {
                    #in: 〈2;v〉
                  }).out
                },
              ]
            }
          }
          "6": (#struct){
            #in: (_){ _ }
            #basic: ((null|string|bytes|number)){ |((int){ int }, (number){ number }, (string){ string }, (bytes){ bytes }, (null){ null }) }
            out: (int){
              1
              let depths#1multi = [
                for k, v in 〈3;#in〉 {
                  (〈6;#next〉 & {
                    #in: 〈2;v〉
                  }).out
                },
              ]
            }
          }
          "7": (#struct){
            #in: (_){ _ }
            #basic: ((null|string|bytes|number)){ |((int){ int }, (number){ number }, (string){ string }, (bytes){ bytes }, (null){ null }) }
            out: (int){
              1
              let depths#1multi = [
                for k, v in 〈3;#in〉 {
                  (〈6;#next〉 & {
                    #in: 〈2;v〉
                  }).out
                },
              ]
            }
          }
          "8": (#struct){
            #in: (_){ _ }
            #basic: ((null|string|bytes|number)){ |((int){ int }, (number){ number }, (string){ string }, (bytes){ bytes }, (null){ null }) }
            out: (int){
              1
              let depths#1multi = [
                for k, v in 〈3;#in〉 {
                  (〈6;#next〉 & {
                    #in: 〈2;v〉
                  }).out
                },
              ]
            }
          }
          "9": (#struct){
            #in: (_){ _ }
            #basic: ((null|string|bytes|number)){ |((int){ int }, (number){ number }, (string){ string }, (bytes){ bytes }, (null){ null }) }
            out: (int){
              1
              let depths#1multi = [
                for k, v in 〈3;#in〉 {
                  (〈6;#next〉 & {
                    #in: 〈2;v〉
                  }).out
                },
              ]
            }
          }
          "10": (#struct){
            #in: (_){ _ }
            #basic: ((null|string|bytes|number)){ |((int){ int }, (number){ number }, (string){ string }, (bytes){ bytes }, (null){ null }) }
            out: (int){
              1
              let depths#1multi = [
                for k, v in 〈3;#in〉 {
                  (〈6;#next〉 & {
                    #in: 〈2;v〉
                  }).out
                },
              ]
            }
          }
        }
        #in: (_){ _ }
        #basic: ((null|string|bytes|number)){ |((int){ int }, (number){ number }, (string){ string }, (bytes){ bytes }, (null){ null }) }
        out: (int){
          1
          let depths#1multi = [
            for k, v in 〈3;#in〉 {
              (〈6;#next〉 & {
                #in: 〈2;v〉
              }).out
            },
          ]
        }
      }
      tree: (struct){
        a: (struct){
          foo: (string){ "bar" }
          a: (struct){
            b: (struct){
              c: (string){ "d" }
            }
          }
        }
        cow: (string){ "moo" }
      }
      d: (#struct){
        #in: (#struct){
          a: (#struct){
            foo: (string){ "bar" }
            a: (#struct){
              b: (#struct){
                c: (string){ "d" }
              }
            }
          }
          cow: (string){ "moo" }
        }
        #maxiter: (int){ 11 }
        #funcFactory: (#struct){
          #next: (_){ _ }
          #func: (#struct){
            #in: (_){ _ }
            #basic: ((null|string|bytes|number)){ |((int){ int }, (number){ number }, (string){ string }, (bytes){ bytes }, (null){ null }) }
            out: (int){
              1
              let depths#1multi = [
                for k, v in 〈3;#in〉 {
                  (〈6;#next〉 & {
                    #in: 〈2;v〉
                  }).out
                },
              ]
            }
          }
        }
        #funcs: (#struct){
          "11": (null){ null }
          "0": (#struct){
            #in: (_){ _ }
            #basic: ((null|string|bytes|number)){ |((int){ int }, (number){ number }, (string){ string }, (bytes){ bytes }, (null){ null }) }
            out: (int){
              1
              let depths#1multi = [
                for k, v in 〈3;#in〉 {
                  (〈6;#next〉 & {
                    #in: 〈2;v〉
                  }).out
                },
              ]
            }
          }
          "1": (#struct){
            #in: (_){ _ }
            #basic: ((null|string|bytes|number)){ |((int){ int }, (number){ number }, (string){ string }, (bytes){ bytes }, (null){ null }) }
            out: (int){
              1
              let depths#1multi = [
                for k, v in 〈3;#in〉 {
                  (〈6;#next〉 & {
                    #in: 〈2;v〉
                  }).out
                },
              ]
            }
          }
          "2": (#struct){
            #in: (_){ _ }
            #basic: ((null|string|bytes|number)){ |((int){ int }, (number){ number }, (string){ string }, (bytes){ bytes }, (null){ null }) }
            out: (int){
              1
              let depths#1multi = [
                for k, v in 〈3;#in〉 {
                  (〈6;#next〉 & {
                    #in: 〈2;v〉
                  }).out
                },
              ]
            }
          }
          "3": (#struct){
            #in: (_){ _ }
            #basic: ((null|string|bytes|number)){ |((int){ int }, (number){ number }, (string){ string }, (bytes){ bytes }, (null){ null }) }
            out: (int){
              1
              let depths#1multi = [
                for k, v in 〈3;#in〉 {
                  (〈6;#next〉 & {
                    #in: 〈2;v〉
                  }).out
                },
              ]
            }
          }
          "4": (#struct){
            #in: (_){ _ }
            #basic: ((null|string|bytes|number)){ |((int){ int }, (number){ number }, (string){ string }, (bytes){ bytes }, (null){ null }) }
            out: (int){
              1
              let depths#1multi = [
                for k, v in 〈3;#in〉 {
                  (〈6;#next〉 & {
                    #in: 〈2;v〉
                  }).out
                },
              ]
            }
          }
          "5": (#struct){
            #in: (_){ _ }
            #basic: ((null|string|bytes|number)){ |((int){ int }, (number){ number }, (string){ string }, (bytes){ bytes }, (null){ null }) }
            out: (int){
              1
              let depths#1multi = [
                for k, v in 〈3;#in〉 {
                  (〈6;#next〉 & {
                    #in: 〈2;v〉
                  }).out
                },
              ]
            }
          }
          "6": (#struct){
            #in: (_){ _ }
            #basic: ((null|string|bytes|number)){ |((int){ int }, (number){ number }, (string){ string }, (bytes){ bytes }, (null){ null }) }
            out: (int){
              1
              let depths#1multi = [
                for k, v in 〈3;#in〉 {
                  (〈6;#next〉 & {
                    #in: 〈2;v〉
                  }).out
                },
              ]
            }
          }
          "7": (#struct){
            #in: (_){ _ }
            #basic: ((null|string|bytes|number)){ |((int){ int }, (number){ number }, (string){ string }, (bytes){ bytes }, (null){ null }) }
            out: (int){
              1
              let depths#1multi = [
                for k, v in 〈3;#in〉 {
                  (〈6;#next〉 & {
                    #in: 〈2;v〉
                  }).out
                },
              ]
            }
          }
          "8": (#struct){
            #in: (_){ _ }
            #basic: ((null|string|bytes|number)){ |((int){ int }, (number){ number }, (string){ string }, (bytes){ bytes }, (null){ null }) }
            out: (int){
              1
              let depths#1multi = [
                for k, v in 〈3;#in〉 {
                  (〈6;#next〉 & {
                    #in: 〈2;v〉
                  }).out
                },
              ]
            }
          }
          "9": (#struct){
            #in: (_){ _ }
            #basic: ((null|string|bytes|number)){ |((int){ int }, (number){ number }, (string){ string }, (bytes){ bytes }, (null){ null }) }
            out: (int){
              1
              let depths#1multi = [
                for k, v in 〈3;#in〉 {
                  (〈6;#next〉 & {
                    #in: 〈2;v〉
                  }).out
                },
              ]
            }
          }
          "10": (#struct){
            #in: (_){ _ }
            #basic: ((null|string|bytes|number)){ |((int){ int }, (number){ number }, (string){ string }, (bytes){ bytes }, (null){ null }) }
            out: (int){
              1
              let depths#1multi = [
                for k, v in 〈3;#in〉 {
                  (〈6;#next〉 & {
                    #in: 〈2;v〉
                  }).out
                },
              ]
            }
          }
        }
        #basic: ((null|string|bytes|number)){ |((int){ int }, (number){ number }, (string){ string }, (bytes){ bytes }, (null){ null }) }
        out: (int){
          5
          let depths#1multi = [
            for k, v in 〈3;#in〉 {
              (〈6;#next〉 & {
                #in: 〈2;v〉
              }).out
            },
          ]
        }
      }
    }
  }
}
-- diff/-out/evalalpha<==>+out/eval --
diff old new
--- old
+++ new
@@ -27,15 +27,11 @@
           }
         }
       }
-      p2: (_|_){
-        // [incomplete] chain.t2.p2.0.1: invalid interpolation: cycle error referencing X:
-        //     ./in.cue:44:6
-        //     ./in.cue:43:28
-        x: (_|_){
-          // [incomplete] chain.t2.p2.0.1: invalid interpolation: cycle error referencing X:
-          //     ./in.cue:44:6
-          //     ./in.cue:43:28
-          x0: (struct){
+      p2: (struct){
+        x: (struct){
+          x0: (struct){
+          }
+          x1: (struct){
           }
         }
         X: (int){ 1 }
@@ -60,9 +56,7 @@
         Depth: (struct){
           #maxiter: (int){ 1 }
           funcs: (struct){
-            "0": (struct){
-              a: (_){ _ }
-            }
+            "0": ~(issue2052.reduced.t1.A)
           }
           a: (_){ _ }
         }
@@ -74,9 +68,7 @@
         Depth: (struct){
           maxiter: (int){ 1 }
           funcs: (struct){
-            "0": (struct){
-              a: (_){ _ }
-            }
+            "0": ~(issue2052.reduced.t2.A)
           }
           a: (_){ _ }
         }
@@ -123,100 +115,100 @@
         }
         tree: (string){ "bar" }
         d: (#struct){
-          #maxiter: (int){ 4 }
-          #funcs: (#struct){
-            "4": (null){ null }
-            "0": (#struct){
-              #in: (_){ _ }
-              #basic: ((null|string)){ |((string){ string }, (null){ null }) }
-              out: (int){ 1 }
-            }
-            "1": (#struct){
-              #in: (_){ _ }
-              #basic: ((null|string)){ |((string){ string }, (null){ null }) }
-              out: (int){ 1 }
-            }
-            "2": (#struct){
-              #in: (_){ _ }
-              #basic: ((null|string)){ |((string){ string }, (null){ null }) }
-              out: (int){ 1 }
-            }
-            "3": (#struct){
-              #in: (_){ _ }
-              #basic: ((null|string)){ |((string){ string }, (null){ null }) }
-              out: (int){ 1 }
-            }
-          }
-          #in: (string){ "bar" }
-          #basic: ((null|string)){ |((string){ string }, (null){ null }) }
-          out: (int){ 1 }
-        }
-      }
-      t2: (struct){
-        #Depth: (#struct){
-          #maxiter: (int){ 4 }
-          #funcs: (#struct){
-            "4": (null){ null }
-            "0": (#struct){
-              #in: (_){ _ }
-              #basic: ((null|string)){ |((string){ string }, (null){ null }) }
-              out: (int){ 1 }
-            }
-            "1": (#struct){
-              #in: (_){ _ }
-              #basic: ((null|string)){ |((string){ string }, (null){ null }) }
-              out: (int){ 1 }
-            }
-            "2": (#struct){
-              #in: (_){ _ }
-              #basic: ((null|string)){ |((string){ string }, (null){ null }) }
-              out: (int){ 1 }
-            }
-            "3": (#struct){
-              #in: (_){ _ }
-              #basic: ((null|string)){ |((string){ string }, (null){ null }) }
-              out: (int){ 1 }
-            }
-          }
-          #in: (_){ _ }
-          #basic: ((null|string)){ |((string){ string }, (null){ null }) }
-          out: (int){ 1 }
-        }
-        #DepthF: (#struct){
-          #next: (_){ _ }
-          #func: (#struct){
-            #in: (_){ _ }
-            #basic: ((null|string)){ |((string){ string }, (null){ null }) }
-            out: (int){ 1 }
-          }
-        }
-        tree: (string){ "bar" }
-        d: (#struct){
-          #maxiter: (int){ 4 }
-          #funcs: (#struct){
-            "4": (null){ null }
-            "0": (#struct){
-              #in: (_){ _ }
-              #basic: ((null|string)){ |((string){ string }, (null){ null }) }
-              out: (int){ 1 }
-            }
-            "1": (#struct){
-              #in: (_){ _ }
-              #basic: ((null|string)){ |((string){ string }, (null){ null }) }
-              out: (int){ 1 }
-            }
-            "2": (#struct){
-              #in: (_){ _ }
-              #basic: ((null|string)){ |((string){ string }, (null){ null }) }
-              out: (int){ 1 }
-            }
-            "3": (#struct){
-              #in: (_){ _ }
-              #basic: ((null|string)){ |((string){ string }, (null){ null }) }
-              out: (int){ 1 }
-            }
-          }
-          #in: (string){ "bar" }
+          #in: (string){ "bar" }
+          #maxiter: (int){ 4 }
+          #funcs: (#struct){
+            "4": (null){ null }
+            "0": (#struct){
+              #in: (_){ _ }
+              #basic: ((null|string)){ |((string){ string }, (null){ null }) }
+              out: (int){ 1 }
+            }
+            "1": (#struct){
+              #in: (_){ _ }
+              #basic: ((null|string)){ |((string){ string }, (null){ null }) }
+              out: (int){ 1 }
+            }
+            "2": (#struct){
+              #in: (_){ _ }
+              #basic: ((null|string)){ |((string){ string }, (null){ null }) }
+              out: (int){ 1 }
+            }
+            "3": (#struct){
+              #in: (_){ _ }
+              #basic: ((null|string)){ |((string){ string }, (null){ null }) }
+              out: (int){ 1 }
+            }
+          }
+          #basic: ((null|string)){ |((string){ string }, (null){ null }) }
+          out: (int){ 1 }
+        }
+      }
+      t2: (struct){
+        #Depth: (#struct){
+          #maxiter: (int){ 4 }
+          #funcs: (#struct){
+            "4": (null){ null }
+            "0": (#struct){
+              #in: (_){ _ }
+              #basic: ((null|string)){ |((string){ string }, (null){ null }) }
+              out: (int){ 1 }
+            }
+            "1": (#struct){
+              #in: (_){ _ }
+              #basic: ((null|string)){ |((string){ string }, (null){ null }) }
+              out: (int){ 1 }
+            }
+            "2": (#struct){
+              #in: (_){ _ }
+              #basic: ((null|string)){ |((string){ string }, (null){ null }) }
+              out: (int){ 1 }
+            }
+            "3": (#struct){
+              #in: (_){ _ }
+              #basic: ((null|string)){ |((string){ string }, (null){ null }) }
+              out: (int){ 1 }
+            }
+          }
+          #in: (_){ _ }
+          #basic: ((null|string)){ |((string){ string }, (null){ null }) }
+          out: (int){ 1 }
+        }
+        #DepthF: (#struct){
+          #next: (_){ _ }
+          #func: (#struct){
+            #in: (_){ _ }
+            #basic: ((null|string)){ |((string){ string }, (null){ null }) }
+            out: (int){ 1 }
+          }
+        }
+        tree: (string){ "bar" }
+        d: (#struct){
+          #in: (string){ "bar" }
+          #maxiter: (int){ 4 }
+          #funcs: (#struct){
+            "4": (null){ null }
+            "0": (#struct){
+              #in: (_){ _ }
+              #basic: ((null|string)){ |((string){ string }, (null){ null }) }
+              out: (int){ 1 }
+            }
+            "1": (#struct){
+              #in: (_){ _ }
+              #basic: ((null|string)){ |((string){ string }, (null){ null }) }
+              out: (int){ 1 }
+            }
+            "2": (#struct){
+              #in: (_){ _ }
+              #basic: ((null|string)){ |((string){ string }, (null){ null }) }
+              out: (int){ 1 }
+            }
+            "3": (#struct){
+              #in: (_){ _ }
+              #basic: ((null|string)){ |((string){ string }, (null){ null }) }
+              out: (int){ 1 }
+            }
+          }
           #basic: ((null|string)){ |((string){ string }, (null){ null }) }
           out: (int){ 1 }
         }
@@ -245,7 +237,13 @@
           #basic: ((null|string|bytes|number)){ |((int){ int }, (number){ number }, (string){ string }, (bytes){ bytes }, (null){ null }) }
           out: (int){
             1
-            let depths#1 = (_){ _ }
+            let depths#1multi = [
+              for k, v in 〈3;#in〉 {
+                (〈6;#next〉 & {
+                  #in: 〈2;v〉
+                }).out
+              },
+            ]
           }
         }
       }
@@ -258,98 +256,170 @@
             #basic: ((null|string|bytes|number)){ |((int){ int }, (number){ number }, (string){ string }, (bytes){ bytes }, (null){ null }) }
             out: (int){
               1
-              let depths#1 = (_){ _ }
-            }
-          }
-        }
-        #funcs: (#struct){
-          "11": (null){ null }
-          "0": (#struct){
-            #in: (_){ _ }
-            #basic: ((null|string|bytes|number)){ |((int){ int }, (number){ number }, (string){ string }, (bytes){ bytes }, (null){ null }) }
-            out: (int){
-              1
-              let depths#1 = (_){ _ }
-            }
-          }
-          "1": (#struct){
-            #in: (_){ _ }
-            #basic: ((null|string|bytes|number)){ |((int){ int }, (number){ number }, (string){ string }, (bytes){ bytes }, (null){ null }) }
-            out: (int){
-              1
-              let depths#1 = (_){ _ }
-            }
-          }
-          "2": (#struct){
-            #in: (_){ _ }
-            #basic: ((null|string|bytes|number)){ |((int){ int }, (number){ number }, (string){ string }, (bytes){ bytes }, (null){ null }) }
-            out: (int){
-              1
-              let depths#1 = (_){ _ }
-            }
-          }
-          "3": (#struct){
-            #in: (_){ _ }
-            #basic: ((null|string|bytes|number)){ |((int){ int }, (number){ number }, (string){ string }, (bytes){ bytes }, (null){ null }) }
-            out: (int){
-              1
-              let depths#1 = (_){ _ }
-            }
-          }
-          "4": (#struct){
-            #in: (_){ _ }
-            #basic: ((null|string|bytes|number)){ |((int){ int }, (number){ number }, (string){ string }, (bytes){ bytes }, (null){ null }) }
-            out: (int){
-              1
-              let depths#1 = (_){ _ }
-            }
-          }
-          "5": (#struct){
-            #in: (_){ _ }
-            #basic: ((null|string|bytes|number)){ |((int){ int }, (number){ number }, (string){ string }, (bytes){ bytes }, (null){ null }) }
-            out: (int){
-              1
-              let depths#1 = (_){ _ }
-            }
-          }
-          "6": (#struct){
-            #in: (_){ _ }
-            #basic: ((null|string|bytes|number)){ |((int){ int }, (number){ number }, (string){ string }, (bytes){ bytes }, (null){ null }) }
-            out: (int){
-              1
-              let depths#1 = (_){ _ }
-            }
-          }
-          "7": (#struct){
-            #in: (_){ _ }
-            #basic: ((null|string|bytes|number)){ |((int){ int }, (number){ number }, (string){ string }, (bytes){ bytes }, (null){ null }) }
-            out: (int){
-              1
-              let depths#1 = (_){ _ }
-            }
-          }
-          "8": (#struct){
-            #in: (_){ _ }
-            #basic: ((null|string|bytes|number)){ |((int){ int }, (number){ number }, (string){ string }, (bytes){ bytes }, (null){ null }) }
-            out: (int){
-              1
-              let depths#1 = (_){ _ }
-            }
-          }
-          "9": (#struct){
-            #in: (_){ _ }
-            #basic: ((null|string|bytes|number)){ |((int){ int }, (number){ number }, (string){ string }, (bytes){ bytes }, (null){ null }) }
-            out: (int){
-              1
-              let depths#1 = (_){ _ }
-            }
-          }
-          "10": (#struct){
-            #in: (_){ _ }
-            #basic: ((null|string|bytes|number)){ |((int){ int }, (number){ number }, (string){ string }, (bytes){ bytes }, (null){ null }) }
-            out: (int){
-              1
-              let depths#1 = (_){ _ }
+              let depths#1multi = [
+                for k, v in 〈3;#in〉 {
+                  (〈6;#next〉 & {
+                    #in: 〈2;v〉
+                  }).out
+                },
+              ]
+            }
+          }
+        }
+        #funcs: (#struct){
+          "11": (null){ null }
+          "0": (#struct){
+            #in: (_){ _ }
+            #basic: ((null|string|bytes|number)){ |((int){ int }, (number){ number }, (string){ string }, (bytes){ bytes }, (null){ null }) }
+            out: (int){
+              1
+              let depths#1multi = [
+                for k, v in 〈3;#in〉 {
+                  (〈6;#next〉 & {
+                    #in: 〈2;v〉
+                  }).out
+                },
+              ]
+            }
+          }
+          "1": (#struct){
+            #in: (_){ _ }
+            #basic: ((null|string|bytes|number)){ |((int){ int }, (number){ number }, (string){ string }, (bytes){ bytes }, (null){ null }) }
+            out: (int){
+              1
+              let depths#1multi = [
+                for k, v in 〈3;#in〉 {
+                  (〈6;#next〉 & {
+                    #in: 〈2;v〉
+                  }).out
+                },
+              ]
+            }
+          }
+          "2": (#struct){
+            #in: (_){ _ }
+            #basic: ((null|string|bytes|number)){ |((int){ int }, (number){ number }, (string){ string }, (bytes){ bytes }, (null){ null }) }
+            out: (int){
+              1
+              let depths#1multi = [
+                for k, v in 〈3;#in〉 {
+                  (〈6;#next〉 & {
+                    #in: 〈2;v〉
+                  }).out
+                },
+              ]
+            }
+          }
+          "3": (#struct){
+            #in: (_){ _ }
+            #basic: ((null|string|bytes|number)){ |((int){ int }, (number){ number }, (string){ string }, (bytes){ bytes }, (null){ null }) }
+            out: (int){
+              1
+              let depths#1multi = [
+                for k, v in 〈3;#in〉 {
+                  (〈6;#next〉 & {
+                    #in: 〈2;v〉
+                  }).out
+                },
+              ]
+            }
+          }
+          "4": (#struct){
+            #in: (_){ _ }
+            #basic: ((null|string|bytes|number)){ |((int){ int }, (number){ number }, (string){ string }, (bytes){ bytes }, (null){ null }) }
+            out: (int){
+              1
+              let depths#1multi = [
+                for k, v in 〈3;#in〉 {
+                  (〈6;#next〉 & {
+                    #in: 〈2;v〉
+                  }).out
+                },
+              ]
+            }
+          }
+          "5": (#struct){
+            #in: (_){ _ }
+            #basic: ((null|string|bytes|number)){ |((int){ int }, (number){ number }, (string){ string }, (bytes){ bytes }, (null){ null }) }
+            out: (int){
+              1
+              let depths#1multi = [
+                for k, v in 〈3;#in〉 {
+                  (〈6;#next〉 & {
+                    #in: 〈2;v〉
+                  }).out
+                },
+              ]
+            }
+          }
+          "6": (#struct){
+            #in: (_){ _ }
+            #basic: ((null|string|bytes|number)){ |((int){ int }, (number){ number }, (string){ string }, (bytes){ bytes }, (null){ null }) }
+            out: (int){
+              1
+              let depths#1multi = [
+                for k, v in 〈3;#in〉 {
+                  (〈6;#next〉 & {
+                    #in: 〈2;v〉
+                  }).out
+                },
+              ]
+            }
+          }
+          "7": (#struct){
+            #in: (_){ _ }
+            #basic: ((null|string|bytes|number)){ |((int){ int }, (number){ number }, (string){ string }, (bytes){ bytes }, (null){ null }) }
+            out: (int){
+              1
+              let depths#1multi = [
+                for k, v in 〈3;#in〉 {
+                  (〈6;#next〉 & {
+                    #in: 〈2;v〉
+                  }).out
+                },
+              ]
+            }
+          }
+          "8": (#struct){
+            #in: (_){ _ }
+            #basic: ((null|string|bytes|number)){ |((int){ int }, (number){ number }, (string){ string }, (bytes){ bytes }, (null){ null }) }
+            out: (int){
+              1
+              let depths#1multi = [
+                for k, v in 〈3;#in〉 {
+                  (〈6;#next〉 & {
+                    #in: 〈2;v〉
+                  }).out
+                },
+              ]
+            }
+          }
+          "9": (#struct){
+            #in: (_){ _ }
+            #basic: ((null|string|bytes|number)){ |((int){ int }, (number){ number }, (string){ string }, (bytes){ bytes }, (null){ null }) }
+            out: (int){
+              1
+              let depths#1multi = [
+                for k, v in 〈3;#in〉 {
+                  (〈6;#next〉 & {
+                    #in: 〈2;v〉
+                  }).out
+                },
+              ]
+            }
+          }
+          "10": (#struct){
+            #in: (_){ _ }
+            #basic: ((null|string|bytes|number)){ |((int){ int }, (number){ number }, (string){ string }, (bytes){ bytes }, (null){ null }) }
+            out: (int){
+              1
+              let depths#1multi = [
+                for k, v in 〈3;#in〉 {
+                  (〈6;#next〉 & {
+                    #in: 〈2;v〉
+                  }).out
+                },
+              ]
             }
           }
         }
@@ -357,7 +427,13 @@
         #basic: ((null|string|bytes|number)){ |((int){ int }, (number){ number }, (string){ string }, (bytes){ bytes }, (null){ null }) }
         out: (int){
           1
-          let depths#1 = (_){ _ }
+          let depths#1multi = [
+            for k, v in 〈3;#in〉 {
+              (〈6;#next〉 & {
+                #in: 〈2;v〉
+              }).out
+            },
+          ]
         }
       }
       tree: (struct){
@@ -371,49 +447,7 @@
         }
         cow: (string){ "moo" }
       }
-      d: (_|_){
-        // [incomplete] issue2052.full.d: cannot add field #maxiter: was already used:
-        //     ./issue2052.cue:143:23
-        #maxiter: (int){ |(*(int){ 4 }, (int){ &(>=0, int) }) }
-        #funcFactory: (#struct){
-          #next: (_){ _ }
-          #func: (#struct){
-            #in: (_){ _ }
-            #basic: ((null|string|bytes|number)){ |((int){ int }, (number){ number }, (string){ string }, (bytes){ bytes }, (null){ null }) }
-            out: (int){
-              1
-              let depths#1 = (_){ _ }
-            }
-          }
-        }
-        #funcs: (#struct){
-          "4": (null){ null }
-          "0": (_){ _ }
-          "1": (#struct){
-            #in: (_){ _ }
-            #basic: ((null|string|bytes|number)){ |((int){ int }, (number){ number }, (string){ string }, (bytes){ bytes }, (null){ null }) }
-            out: (int){
-              1
-              let depths#1 = (_){ _ }
-            }
-          }
-          "2": (#struct){
-            #in: (_){ _ }
-            #basic: ((null|string|bytes|number)){ |((int){ int }, (number){ number }, (string){ string }, (bytes){ bytes }, (null){ null }) }
-            out: (int){
-              1
-              let depths#1 = (_){ _ }
-            }
-          }
-          "3": (#struct){
-            #in: (_){ _ }
-            #basic: ((null|string|bytes|number)){ |((int){ int }, (number){ number }, (string){ string }, (bytes){ bytes }, (null){ null }) }
-            out: (int){
-              1
-              let depths#1 = (_){ _ }
-            }
-          }
-        }
+      d: (#struct){
         #in: (#struct){
           a: (#struct){
             foo: (string){ "bar" }
@@ -425,6 +459,192 @@
           }
           cow: (string){ "moo" }
         }
+        #maxiter: (int){ 11 }
+        #funcFactory: (#struct){
+          #next: (_){ _ }
+          #func: (#struct){
+            #in: (_){ _ }
+            #basic: ((null|string|bytes|number)){ |((int){ int }, (number){ number }, (string){ string }, (bytes){ bytes }, (null){ null }) }
+            out: (int){
+              1
+              let depths#1multi = [
+                for k, v in 〈3;#in〉 {
+                  (〈6;#next〉 & {
+                    #in: 〈2;v〉
+                  }).out
+                },
+              ]
+            }
+          }
+        }
+        #funcs: (#struct){
+          "11": (null){ null }
+          "0": (#struct){
+            #in: (_){ _ }
+            #basic: ((null|string|bytes|number)){ |((int){ int }, (number){ number }, (string){ string }, (bytes){ bytes }, (null){ null }) }
+            out: (int){
+              1
+              let depths#1multi = [
+                for k, v in 〈3;#in〉 {
+                  (〈6;#next〉 & {
+                    #in: 〈2;v〉
+                  }).out
+                },
+              ]
+            }
+          }
+          "1": (#struct){
+            #in: (_){ _ }
+            #basic: ((null|string|bytes|number)){ |((int){ int }, (number){ number }, (string){ string }, (bytes){ bytes }, (null){ null }) }
+            out: (int){
+              1
+              let depths#1multi = [
+                for k, v in 〈3;#in〉 {
+                  (〈6;#next〉 & {
+                    #in: 〈2;v〉
+                  }).out
+                },
+              ]
+            }
+          }
+          "2": (#struct){
+            #in: (_){ _ }
+            #basic: ((null|string|bytes|number)){ |((int){ int }, (number){ number }, (string){ string }, (bytes){ bytes }, (null){ null }) }
+            out: (int){
+              1
+              let depths#1multi = [
+                for k, v in 〈3;#in〉 {
+                  (〈6;#next〉 & {
+                    #in: 〈2;v〉
+                  }).out
+                },
+              ]
+            }
+          }
+          "3": (#struct){
+            #in: (_){ _ }
+            #basic: ((null|string|bytes|number)){ |((int){ int }, (number){ number }, (string){ string }, (bytes){ bytes }, (null){ null }) }
+            out: (int){
+              1
+              let depths#1multi = [
+                for k, v in 〈3;#in〉 {
+                  (〈6;#next〉 & {
+                    #in: 〈2;v〉
+                  }).out
+                },
+              ]
+            }
+          }
+          "4": (#struct){
+            #in: (_){ _ }
+            #basic: ((null|string|bytes|number)){ |((int){ int }, (number){ number }, (string){ string }, (bytes){ bytes }, (null){ null }) }
+            out: (int){
+              1
+              let depths#1multi = [
+                for k, v in 〈3;#in〉 {
+                  (〈6;#next〉 & {
+                    #in: 〈2;v〉
+                  }).out
+                },
+              ]
+            }
+          }
+          "5": (#struct){
+            #in: (_){ _ }
+            #basic: ((null|string|bytes|number)){ |((int){ int }, (number){ number }, (string){ string }, (bytes){ bytes }, (null){ null }) }
+            out: (int){
+              1
+              let depths#1multi = [
+                for k, v in 〈3;#in〉 {
+                  (〈6;#next〉 & {
+                    #in: 〈2;v〉
+                  }).out
+                },
+              ]
+            }
+          }
+          "6": (#struct){
+            #in: (_){ _ }
+            #basic: ((null|string|bytes|number)){ |((int){ int }, (number){ number }, (string){ string }, (bytes){ bytes }, (null){ null }) }
+            out: (int){
+              1
+              let depths#1multi = [
+                for k, v in 〈3;#in〉 {
+                  (〈6;#next〉 & {
+                    #in: 〈2;v〉
+                  }).out
+                },
+              ]
+            }
+          }
+          "7": (#struct){
+            #in: (_){ _ }
+            #basic: ((null|string|bytes|number)){ |((int){ int }, (number){ number }, (string){ string }, (bytes){ bytes }, (null){ null }) }
+            out: (int){
+              1
+              let depths#1multi = [
+                for k, v in 〈3;#in〉 {
+                  (〈6;#next〉 & {
+                    #in: 〈2;v〉
+                  }).out
+                },
+              ]
+            }
+          }
+          "8": (#struct){
+            #in: (_){ _ }
+            #basic: ((null|string|bytes|number)){ |((int){ int }, (number){ number }, (string){ string }, (bytes){ bytes }, (null){ null }) }
+            out: (int){
+              1
+              let depths#1multi = [
+                for k, v in 〈3;#in〉 {
+                  (〈6;#next〉 & {
+                    #in: 〈2;v〉
+                  }).out
+                },
+              ]
+            }
+          }
+          "9": (#struct){
+            #in: (_){ _ }
+            #basic: ((null|string|bytes|number)){ |((int){ int }, (number){ number }, (string){ string }, (bytes){ bytes }, (null){ null }) }
+            out: (int){
+              1
+              let depths#1multi = [
+                for k, v in 〈3;#in〉 {
+                  (〈6;#next〉 & {
+                    #in: 〈2;v〉
+                  }).out
+                },
+              ]
+            }
+          }
+          "10": (#struct){
+            #in: (_){ _ }
+            #basic: ((null|string|bytes|number)){ |((int){ int }, (number){ number }, (string){ string }, (bytes){ bytes }, (null){ null }) }
+            out: (int){
+              1
+              let depths#1multi = [
+                for k, v in 〈3;#in〉 {
+                  (〈6;#next〉 & {
+                    #in: 〈2;v〉
+                  }).out
+                },
+              ]
+            }
+          }
+        }
+        #basic: ((null|string|bytes|number)){ |((int){ int }, (number){ number }, (string){ string }, (bytes){ bytes }, (null){ null }) }
+        out: (int){
+          5
+          let depths#1multi = [
+            for k, v in 〈3;#in〉 {
+              (〈6;#next〉 & {
+                #in: 〈2;v〉
+              }).out
+            },
+          ]
+        }
       }
     }
   }
-- out/evalalpha/stats --
Leaks:  3149
Freed:  0
Reused: 0
Allocs: 3149
Retain: 0

Unifications: 940
Conjuncts:    5024
Disjuncts:    1615

CloseIDElems: 21726
NumCloseIDs: 1548
-- diff/-out/evalalpha/stats<==>+out/eval/stats --
diff old new
--- old
+++ new
@@ -1,9 +1,12 @@
-Leaks:  56
-Freed:  1788
-Reused: 1774
-Allocs: 70
-Retain: 174
-
-Unifications: 759
-Conjuncts:    3139
-Disjuncts:    1942
+Leaks:  3149
+Freed:  0
+Reused: 0
+Allocs: 3149
+Retain: 0
+
+Unifications: 940
+Conjuncts:    5024
+Disjuncts:    1615
+
+CloseIDElems: 21726
+NumCloseIDs: 1548
-- out/eval/stats --
Leaks:  56
Freed:  1788
Reused: 1774
Allocs: 70
Retain: 174

Unifications: 759
Conjuncts:    3139
Disjuncts:    1942
-- out/eval --
(struct){
  chain: (struct){
    t1: (struct){
      #maxiter: (int){ 2 }
      x: (#struct){
      }
      a: (struct){
        x2: (null){ null }
        x0: (#struct){
        }
        x1: (#struct){
        }
      }
      #DepthF: (#struct){
        #in: (_){ _ }
        #out: (#struct){
        }
      }
    }
    t2: (struct){
      p1: (struct){
        X: (int){ 1 }
        x: (struct){
          x0: (struct){
          }
          x1: (struct){
          }
        }
      }
      p2: (_|_){
        // [incomplete] chain.t2.p2.0.1: invalid interpolation: cycle error referencing X:
        //     ./in.cue:44:6
        //     ./in.cue:43:28
        x: (_|_){
          // [incomplete] chain.t2.p2.0.1: invalid interpolation: cycle error referencing X:
          //     ./in.cue:44:6
          //     ./in.cue:43:28
          x0: (struct){
          }
        }
        X: (int){ 1 }
      }
    }
    t3: (struct){
      p1: (struct){
        X: (int){ 1 }
        x: (struct){
          x0: (struct){
          }
        }
      }
    }
  }
  issue2052: (struct){
    reduced: (struct){
      t1: (struct){
        A: (struct){
          a: (_){ _ }
        }
        Depth: (struct){
          #maxiter: (int){ 1 }
          funcs: (struct){
            "0": (struct){
              a: (_){ _ }
            }
          }
          a: (_){ _ }
        }
      }
      t2: (struct){
        A: (struct){
          a: (_){ _ }
        }
        Depth: (struct){
          maxiter: (int){ 1 }
          funcs: (struct){
            "0": (struct){
              a: (_){ _ }
            }
          }
          a: (_){ _ }
        }
      }
    }
    medium: (struct){
      t1: (struct){
        #Depth: (#struct){
          #maxiter: (int){ 4 }
          #funcs: (#struct){
            "4": (null){ null }
            "0": (#struct){
              #in: (_){ _ }
              #basic: ((null|string)){ |((string){ string }, (null){ null }) }
              out: (int){ 1 }
            }
            "1": (#struct){
              #in: (_){ _ }
              #basic: ((null|string)){ |((string){ string }, (null){ null }) }
              out: (int){ 1 }
            }
            "2": (#struct){
              #in: (_){ _ }
              #basic: ((null|string)){ |((string){ string }, (null){ null }) }
              out: (int){ 1 }
            }
            "3": (#struct){
              #in: (_){ _ }
              #basic: ((null|string)){ |((string){ string }, (null){ null }) }
              out: (int){ 1 }
            }
          }
          #in: (_){ _ }
          #basic: ((null|string)){ |((string){ string }, (null){ null }) }
          out: (int){ 1 }
        }
        #DepthF: (#struct){
          #next: (_){ _ }
          #func: (#struct){
            #in: (_){ _ }
            #basic: ((null|string)){ |((string){ string }, (null){ null }) }
            out: (int){ 1 }
          }
        }
        tree: (string){ "bar" }
        d: (#struct){
          #maxiter: (int){ 4 }
          #funcs: (#struct){
            "4": (null){ null }
            "0": (#struct){
              #in: (_){ _ }
              #basic: ((null|string)){ |((string){ string }, (null){ null }) }
              out: (int){ 1 }
            }
            "1": (#struct){
              #in: (_){ _ }
              #basic: ((null|string)){ |((string){ string }, (null){ null }) }
              out: (int){ 1 }
            }
            "2": (#struct){
              #in: (_){ _ }
              #basic: ((null|string)){ |((string){ string }, (null){ null }) }
              out: (int){ 1 }
            }
            "3": (#struct){
              #in: (_){ _ }
              #basic: ((null|string)){ |((string){ string }, (null){ null }) }
              out: (int){ 1 }
            }
          }
          #in: (string){ "bar" }
          #basic: ((null|string)){ |((string){ string }, (null){ null }) }
          out: (int){ 1 }
        }
      }
      t2: (struct){
        #Depth: (#struct){
          #maxiter: (int){ 4 }
          #funcs: (#struct){
            "4": (null){ null }
            "0": (#struct){
              #in: (_){ _ }
              #basic: ((null|string)){ |((string){ string }, (null){ null }) }
              out: (int){ 1 }
            }
            "1": (#struct){
              #in: (_){ _ }
              #basic: ((null|string)){ |((string){ string }, (null){ null }) }
              out: (int){ 1 }
            }
            "2": (#struct){
              #in: (_){ _ }
              #basic: ((null|string)){ |((string){ string }, (null){ null }) }
              out: (int){ 1 }
            }
            "3": (#struct){
              #in: (_){ _ }
              #basic: ((null|string)){ |((string){ string }, (null){ null }) }
              out: (int){ 1 }
            }
          }
          #in: (_){ _ }
          #basic: ((null|string)){ |((string){ string }, (null){ null }) }
          out: (int){ 1 }
        }
        #DepthF: (#struct){
          #next: (_){ _ }
          #func: (#struct){
            #in: (_){ _ }
            #basic: ((null|string)){ |((string){ string }, (null){ null }) }
            out: (int){ 1 }
          }
        }
        tree: (string){ "bar" }
        d: (#struct){
          #maxiter: (int){ 4 }
          #funcs: (#struct){
            "4": (null){ null }
            "0": (#struct){
              #in: (_){ _ }
              #basic: ((null|string)){ |((string){ string }, (null){ null }) }
              out: (int){ 1 }
            }
            "1": (#struct){
              #in: (_){ _ }
              #basic: ((null|string)){ |((string){ string }, (null){ null }) }
              out: (int){ 1 }
            }
            "2": (#struct){
              #in: (_){ _ }
              #basic: ((null|string)){ |((string){ string }, (null){ null }) }
              out: (int){ 1 }
            }
            "3": (#struct){
              #in: (_){ _ }
              #basic: ((null|string)){ |((string){ string }, (null){ null }) }
              out: (int){ 1 }
            }
          }
          #in: (string){ "bar" }
          #basic: ((null|string)){ |((string){ string }, (null){ null }) }
          out: (int){ 1 }
        }
      }
    }
    full: (struct){
      #RecurseN: (_){
        _
        #maxiter: (int){ |(*(int){ 4 }, (int){ &(>=0, int) }) }
        #funcFactory: (#struct){
          #next: (_){ _ }
          #func: (_){ _ }
        }
        #funcs: (#struct){
          "4": (null){ null }
          "0": (_){ _ }
          "1": (_){ _ }
          "2": (_){ _ }
          "3": (_){ _ }
        }
      }
      #DepthF: (#struct){
        #next: (_){ _ }
        #func: (#struct){
          #in: (_){ _ }
          #basic: ((null|string|bytes|number)){ |((int){ int }, (number){ number }, (string){ string }, (bytes){ bytes }, (null){ null }) }
          out: (int){
            1
            let depths#1 = (_){ _ }
          }
        }
      }
      #Depth: (#struct){
        #maxiter: (int){ 11 }
        #funcFactory: (#struct){
          #next: (_){ _ }
          #func: (#struct){
            #in: (_){ _ }
            #basic: ((null|string|bytes|number)){ |((int){ int }, (number){ number }, (string){ string }, (bytes){ bytes }, (null){ null }) }
            out: (int){
              1
              let depths#1 = (_){ _ }
            }
          }
        }
        #funcs: (#struct){
          "11": (null){ null }
          "0": (#struct){
            #in: (_){ _ }
            #basic: ((null|string|bytes|number)){ |((int){ int }, (number){ number }, (string){ string }, (bytes){ bytes }, (null){ null }) }
            out: (int){
              1
              let depths#1 = (_){ _ }
            }
          }
          "1": (#struct){
            #in: (_){ _ }
            #basic: ((null|string|bytes|number)){ |((int){ int }, (number){ number }, (string){ string }, (bytes){ bytes }, (null){ null }) }
            out: (int){
              1
              let depths#1 = (_){ _ }
            }
          }
          "2": (#struct){
            #in: (_){ _ }
            #basic: ((null|string|bytes|number)){ |((int){ int }, (number){ number }, (string){ string }, (bytes){ bytes }, (null){ null }) }
            out: (int){
              1
              let depths#1 = (_){ _ }
            }
          }
          "3": (#struct){
            #in: (_){ _ }
            #basic: ((null|string|bytes|number)){ |((int){ int }, (number){ number }, (string){ string }, (bytes){ bytes }, (null){ null }) }
            out: (int){
              1
              let depths#1 = (_){ _ }
            }
          }
          "4": (#struct){
            #in: (_){ _ }
            #basic: ((null|string|bytes|number)){ |((int){ int }, (number){ number }, (string){ string }, (bytes){ bytes }, (null){ null }) }
            out: (int){
              1
              let depths#1 = (_){ _ }
            }
          }
          "5": (#struct){
            #in: (_){ _ }
            #basic: ((null|string|bytes|number)){ |((int){ int }, (number){ number }, (string){ string }, (bytes){ bytes }, (null){ null }) }
            out: (int){
              1
              let depths#1 = (_){ _ }
            }
          }
          "6": (#struct){
            #in: (_){ _ }
            #basic: ((null|string|bytes|number)){ |((int){ int }, (number){ number }, (string){ string }, (bytes){ bytes }, (null){ null }) }
            out: (int){
              1
              let depths#1 = (_){ _ }
            }
          }
          "7": (#struct){
            #in: (_){ _ }
            #basic: ((null|string|bytes|number)){ |((int){ int }, (number){ number }, (string){ string }, (bytes){ bytes }, (null){ null }) }
            out: (int){
              1
              let depths#1 = (_){ _ }
            }
          }
          "8": (#struct){
            #in: (_){ _ }
            #basic: ((null|string|bytes|number)){ |((int){ int }, (number){ number }, (string){ string }, (bytes){ bytes }, (null){ null }) }
            out: (int){
              1
              let depths#1 = (_){ _ }
            }
          }
          "9": (#struct){
            #in: (_){ _ }
            #basic: ((null|string|bytes|number)){ |((int){ int }, (number){ number }, (string){ string }, (bytes){ bytes }, (null){ null }) }
            out: (int){
              1
              let depths#1 = (_){ _ }
            }
          }
          "10": (#struct){
            #in: (_){ _ }
            #basic: ((null|string|bytes|number)){ |((int){ int }, (number){ number }, (string){ string }, (bytes){ bytes }, (null){ null }) }
            out: (int){
              1
              let depths#1 = (_){ _ }
            }
          }
        }
        #in: (_){ _ }
        #basic: ((null|string|bytes|number)){ |((int){ int }, (number){ number }, (string){ string }, (bytes){ bytes }, (null){ null }) }
        out: (int){
          1
          let depths#1 = (_){ _ }
        }
      }
      tree: (struct){
        a: (struct){
          foo: (string){ "bar" }
          a: (struct){
            b: (struct){
              c: (string){ "d" }
            }
          }
        }
        cow: (string){ "moo" }
      }
      d: (_|_){
        // [incomplete] issue2052.full.d: cannot add field #maxiter: was already used:
        //     ./issue2052.cue:143:23
        #maxiter: (int){ |(*(int){ 4 }, (int){ &(>=0, int) }) }
        #funcFactory: (#struct){
          #next: (_){ _ }
          #func: (#struct){
            #in: (_){ _ }
            #basic: ((null|string|bytes|number)){ |((int){ int }, (number){ number }, (string){ string }, (bytes){ bytes }, (null){ null }) }
            out: (int){
              1
              let depths#1 = (_){ _ }
            }
          }
        }
        #funcs: (#struct){
          "4": (null){ null }
          "0": (_){ _ }
          "1": (#struct){
            #in: (_){ _ }
            #basic: ((null|string|bytes|number)){ |((int){ int }, (number){ number }, (string){ string }, (bytes){ bytes }, (null){ null }) }
            out: (int){
              1
              let depths#1 = (_){ _ }
            }
          }
          "2": (#struct){
            #in: (_){ _ }
            #basic: ((null|string|bytes|number)){ |((int){ int }, (number){ number }, (string){ string }, (bytes){ bytes }, (null){ null }) }
            out: (int){
              1
              let depths#1 = (_){ _ }
            }
          }
          "3": (#struct){
            #in: (_){ _ }
            #basic: ((null|string|bytes|number)){ |((int){ int }, (number){ number }, (string){ string }, (bytes){ bytes }, (null){ null }) }
            out: (int){
              1
              let depths#1 = (_){ _ }
            }
          }
        }
        #in: (#struct){
          a: (#struct){
            foo: (string){ "bar" }
            a: (#struct){
              b: (#struct){
                c: (string){ "d" }
              }
            }
          }
          cow: (string){ "moo" }
        }
      }
    }
  }
}
-- out/compile --
--- in.cue
{
  chain: {
    t1: {
      #maxiter: 2
      x: 〈0;a〉.x0
      a: {
        for k, _ in [
          0,
          1,
        ] {
          "x\(〈1;k〉)": (〈3;#DepthF〉 & {
            #in: 〈4;a〉["x\((〈2;k〉 + 1))"]
          }).#out
        }
      }
      a: {
        x2: null
      }
      #DepthF: {
        #in: _
        #out: {}
      }
    }
  }
  chain: {
    t2: {
      p1: {
        X: 1
        for _, v in 〈import;list〉.Concat([
          [
            0,
            〈2;X〉,
          ],
          [],
        ]) {
          x: {
            "x\(〈2;v〉)": {}
          }
        }
        x: _
        〈0;x〉.x0
      }
    }
  }
  chain: {
    t2: {
      p2: {
        for _, v in 〈import;list〉.Concat([
          [
            0,
            〈2;X〉,
          ],
          [],
        ]) {
          x: {
            "x\(〈2;v〉)": {}
          }
        }
        x: _
        〈0;x〉.x0
        X: 1
      }
    }
  }
  chain: {
    t3: {
      p1: {
        X: 1
        for _, v in 〈import;list〉.Range(0, 〈0;X〉, 1) {
          x: {
            "x\(〈2;v〉)": {}
          }
        }
        x: _
        〈0;x〉.x0
      }
    }
  }
  chain: {
    t3: {
      p1: {
        for _, v in 〈import;list〉.Range(0, 〈0;X〉, 1) {
          x: {
            "x\(〈2;v〉)": {}
          }
        }
        x: _
        〈0;x〉.x0
        X: 1
      }
    }
  }
}
--- issue2052.cue
{
  issue2052: {
    reduced: {
      t1: {
        A: {
          a: _
        }
        Depth: {
          #maxiter: 1
          if (〈import;math〉.Abs(〈0;#maxiter〉) == 1) {
            funcs: {
              "\(0)": 〈3;A〉
            }
          }
          funcs: {}
          〈0;funcs〉["0"]
        }
      }
    }
  }
  issue2052: {
    reduced: {
      t2: {
        A: {
          a: _
        }
        Depth: {
          maxiter: 1
          for k, v in 〈import;list〉.Range(0, 〈0;maxiter〉, 1) {
            funcs: {
              "\(0)": 〈4;A〉
            }
          }
          funcs: {}
          〈0;funcs〉["0"]
        }
      }
    }
  }
  issue2052: {
    medium: {
      t1: {
        #Depth: {
          #maxiter: 4
          for k, v in 〈import;list〉.Range(0, 〈0;#maxiter〉, 1) {
            #funcs: {
              "\(〈2;k〉)": (〈4;#DepthF〉 & {
                #next: 〈2;#funcs〉["\((〈3;k〉 + 1))"]
              }).#func
            }
          }
          #funcs: {
            "\(〈1;#maxiter〉)": null
          }
          〈0;#funcs〉["0"]
        }
        #DepthF: {
          #next: _
          #func: {
            #in: _
            #basic: (string|null)
            out: {
              if ((〈1;#in〉 & 〈1;#basic〉) != _|_(explicit error (_|_ literal) in source)) {
                1
              }
              if ((〈1;#in〉 & 〈1;#basic〉) == _|_(explicit error (_|_ literal) in source)) {
                (〈import;list〉.Max([
                  for k, v in 〈3;#in〉 {
                    (〈6;#next〉 & {
                      #in: 〈2;v〉
                    }).out
                  },
                ]) + 1)
              }
            }
          }
        }
        tree: "bar"
        d: (〈0;#Depth〉 & {
          #in: 〈1;tree〉
        })
      }
    }
  }
  issue2052: {
    medium: {
      t2: {
        #Depth: {
          #maxiter: 4
          for k, v in 〈import;list〉.Range(0, 〈0;#maxiter〉, 1) {
            #funcs: {
              "\(〈2;k〉)": (〈4;#DepthF〉 & {
                #next: 〈2;#funcs〉["\((〈3;k〉 + 1))"]
              }).#func
            }
          }
          #funcs: {
            for k, v in 〈import;list〉.Range(0, 〈1;#maxiter〉, 1) {
              "\(〈1;k〉)": (〈4;#DepthF〉 & {
                #next: 〈4;#funcs〉["\((〈2;k〉 + 1))"]
              }).#func
            }
          }
          #funcs: {
            "\(〈1;#maxiter〉)": null
          }
          〈0;#funcs〉["0"]
        }
        #DepthF: {
          #next: _
          #func: {
            #in: _
            #basic: (string|null)
            out: {
              if ((〈1;#in〉 & 〈1;#basic〉) != _|_(explicit error (_|_ literal) in source)) {
                1
              }
              if ((〈1;#in〉 & 〈1;#basic〉) == _|_(explicit error (_|_ literal) in source)) {
                (〈import;list〉.Max([
                  for k, v in 〈3;#in〉 {
                    (〈6;#next〉 & {
                      #in: 〈2;v〉
                    }).out
                  },
                ]) + 1)
              }
            }
          }
        }
        tree: "bar"
        d: (〈0;#Depth〉 & {
          #in: 〈1;tree〉
        })
      }
    }
  }
  issue2052: {
    full: {
      #RecurseN: {
        #maxiter: (&(int, >=0)|*4)
        #funcFactory: {
          #next: _
          #func: _
        }
        for k, v in 〈import;list〉.Range(0, 〈0;#maxiter〉, 1) {
          #funcs: {
            "\(〈2;k〉)": (〈3;#funcFactory〉 & {
              #next: 〈2;#funcs〉["\((〈3;k〉 + 1))"]
            }).#func
          }
        }
        #funcs: {
          "\(〈1;#maxiter〉)": null
        }
        〈0;#funcs〉["0"]
      }
      #DepthF: {
        #next: _
        #func: {
          #in: _
          #basic: (int|number|string|bytes|null)
          out: {
            if ((〈1;#in〉 & 〈1;#basic〉) != _|_(explicit error (_|_ literal) in source)) {
              1
            }
            if ((〈1;#in〉 & 〈1;#basic〉) == _|_(explicit error (_|_ literal) in source)) {
              let depths#1 = [
                for k, v in 〈3;#in〉 {
                  (〈6;#next〉 & {
                    #in: 〈2;v〉
                  }).out
                },
              ]
              (〈import;list〉.Max(〈0;let depths#1〉) + 1)
            }
          }
        }
      }
      #Depth: (〈0;#RecurseN〉 & {
        #maxiter: 11
        #funcFactory: 〈1;#DepthF〉
      })
      tree: {
        a: {
          foo: "bar"
          a: {
            b: {
              c: "d"
            }
          }
        }
        cow: "moo"
      }
      d: (〈0;#Depth〉 & {
        #in: 〈1;tree〉
      })
    }
  }
}
