-- in.cue --
a: {
	foo: a: 1
	[X = =~"foo"]: {
		b:    1
		name: X
	}
}
d: a & {
	"foobar": {
		c: 2
	}
}

t1: {
	#a: {
		[>"e" & <"z"]: int
	}
	b: #a & {f: 4}
	c: #a & {z: 4}
}

t2: {
	#a: {
		["x" | "y"]: int
	}
	b: #a & {x: 4}
	c: #a & {z: 4}
}

-- issue2109.cue --
// Detect cycle:
// The pattern constraint of FlagsURLS is applied to countries (because
// FlagsURLs  is embedded. But the pattern constraint itself refers to
// countries. So countries -> or(countries) -> countries.
//
// Theoretically, or(countries) can be resolved without a cycle. And then we
// could see it does not apply to countries. For now we stick with this
// approach understanding that it is easier to relax later.
patternCycle: issue2109: p1: {
	countries: ["US", "GB", "AU"]
	FlagsURLs: {[or(countries)]: string}
	FlagsURLs
}
patternCycle: issue2109: p2: {
	FlagsURLs: {[or(countries)]: string}
	FlagsURLs
	countries: ["US", "GB", "AU"]
}
patternCycle: issue2109: p3: {
	FlagsURLs
	FlagsURLs: {[or(countries)]: string}
	countries: ["US", "GB", "AU"]
}

patternCycle: t1: p1: {
	countries: "US" | "GB" | "AU"
	FlagsURLs: {[countries]: string}
	FlagsURLs
}
patternCycle: t1: p2: {
	FlagsURLs
	countries: "US" | "GB" | "AU"
	FlagsURLs: {[countries]: string}
}
patternCycle: t1: p3: {
	FlagsURLs
	FlagsURLs: {[countries]: string}
	countries: "US" | "GB" | "AU"
}

-- intpattern.cue --
issue3670: {
	#X: [int]: string
	a: #X
	a: "not_int": "c"
}
dual: {
	_
	// As long as it is undecided whether this is a struct or list, this should
	// not be a conflict. Note that the spec does not allow int patterns, but
	// both v2 and v3 allow it, and we soon will, so it seems gratuitous to
	// break it now.
	[string]: _
	[int]: _
}
-- multi.cue --
// Ensure that if the same pattern is added multiple times in different
// contexts, it is added to all contexts to preserve closedness information.
issue3638: full: {
	routes: default: {}
	routes: [string]: spec: [{
		refs: [{"default"}]
	}]
	#Fields: {
		input: _
		output: [for x in input { x }]
		...
	}
	#Kubernetes: {
		#Fields & {
			Routes: route: [_]: spec!: HTTPROUTESPEC.#x
		}
		#Fields // Commenting out this line also fixes evalv3.
		Routes: _
		input: res1: Routes
	}
	let HTTPROUTESPEC = {
		#x: [...{
			refs: [...{string}]
		}] | *[{
			other: []
		}]
	}

	// Order dependent! Breaks if the lines below are moved to the top of the file.
	entrypoint: used.output
	used: #Kubernetes & {
		Routes: route: routes
	}
}
issue3638: reduced: {
	input: k1: [string]: a: 1
	input: k1: foo: #x
	out: {
		for x in input { x }
		for x in input { x }
	}
	#x: { a: int } | *{ b: 2 }
}
// We expect that changing the pattern constraint into a field should give
// not materially change the outcome.
issue3638: compare: {
	input: k1: foo: a: 1
	input: k1: foo: #x
	out: {
		for x in input { x }
		for x in input { x }
	}
	#x: { a: int } | *{ b: 2 }
}
-- out/evalalpha/stats --
Leaks:  302
Freed:  0
Reused: 0
Allocs: 302
Retain: 0

Unifications: 229
Conjuncts:    453
Disjuncts:    53

CloseIDElems: 121
NumCloseIDs: 125
-- diff/-out/evalalpha/stats<==>+out/eval/stats --
diff old new
--- old
+++ new
@@ -1,9 +1,12 @@
-Leaks:  4
-Freed:  269
-Reused: 250
-Allocs: 23
-Retain: 30
-
-Unifications: 214
-Conjuncts:    639
-Disjuncts:    297
+Leaks:  302
+Freed:  0
+Reused: 0
+Allocs: 302
+Retain: 0
+
+Unifications: 229
+Conjuncts:    453
+Disjuncts:    53
+
+CloseIDElems: 121
+NumCloseIDs: 125
-- out/eval/stats --
Leaks:  4
Freed:  269
Reused: 250
Allocs: 23
Retain: 30

Unifications: 214
Conjuncts:    639
Disjuncts:    297
-- out/evalalpha --
Errors:
issue3670.a.not_int: field not allowed:
    ./intpattern.cue:4:5
t1.c.z: field not allowed:
    ./in.cue:19:11
t2.c.z: field not allowed:
    ./in.cue:27:11

Result:
(_|_){
  // [eval]
  a: (struct){
    foo: (struct){
      a: (int){ 1 }
      b: (int){ 1 }
      name: (string){ "foo" }
    }
  }
  d: (struct){
    foobar: (struct){
      c: (int){ 2 }
      b: (int){ 1 }
      name: (string){ "foobar" }
    }
    foo: (struct){
      a: (int){ 1 }
      b: (int){ 1 }
      name: (string){ "foo" }
    }
  }
  t1: (_|_){
    // [eval]
    #a: (#struct){
    }
    b: (#struct){
      f: (int){ 4 }
    }
    c: (_|_){
      // [eval]
      z: (_|_){
        // [eval] t1.c.z: field not allowed:
        //     ./in.cue:19:11
      }
    }
  }
  t2: (_|_){
    // [eval]
    #a: (#struct){
    }
    b: (#struct){
      x: (int){ 4 }
    }
    c: (_|_){
      // [eval]
      z: (_|_){
        // [eval] t2.c.z: field not allowed:
        //     ./in.cue:27:11
      }
    }
  }
  issue3670: (_|_){
    // [eval]
    #X: (#struct){
    }
    a: (_|_){
      // [eval]
      not_int: (_|_){
        // [eval] issue3670.a.not_int: field not allowed:
        //     ./intpattern.cue:4:5
      }
    }
  }
  dual: (_){ _ }
  patternCycle: (struct){
    issue2109: (struct){
      p1: (struct){
        countries: (#list){
          0: (string){ "US" }
          1: (string){ "GB" }
          2: (string){ "AU" }
        }
        FlagsURLs: (struct){
        }
      }
      p2: (struct){
        FlagsURLs: (struct){
        }
        countries: (#list){
          0: (string){ "US" }
          1: (string){ "GB" }
          2: (string){ "AU" }
        }
      }
      p3: (struct){
        FlagsURLs: (struct){
        }
        countries: (#list){
          0: (string){ "US" }
          1: (string){ "GB" }
          2: (string){ "AU" }
        }
      }
    }
    t1: (struct){
      p1: (struct){
        countries: (string){ |((string){ "US" }, (string){ "GB" }, (string){ "AU" }) }
        FlagsURLs: (struct){
        }
      }
      p2: (struct){
        countries: (string){ |((string){ "US" }, (string){ "GB" }, (string){ "AU" }) }
        FlagsURLs: (struct){
        }
      }
      p3: (struct){
        FlagsURLs: (struct){
        }
        countries: (string){ |((string){ "US" }, (string){ "GB" }, (string){ "AU" }) }
      }
    }
  }
  issue3638: (struct){
    full: (struct){
      routes: (struct){
        default: (struct){
          spec: (#list){
            0: (struct){
              refs: (#list){
                0: (string){ "default" }
              }
            }
          }
        }
      }
      #Fields: (#struct){
        input: (_){ _ }
        output: (_|_){
          // [incomplete] issue3638.full.#Fields.output: cannot range over input (incomplete type _):
          //     ./multi.cue:10:21
        }
      }
      #Kubernetes: (#struct){
        Routes: (#struct){
          route: (#struct){
          }
        }
        input: (#struct){
          res1: ~(issue3638.full.#Kubernetes.Routes)
        }
        output: (#list){
          0: (#struct){
            route: (#struct){
            }
          }
        }
      }
      let HTTPROUTESPEC#1 = (struct){
        #x: (#list){ |(*(#list){
            0: (#struct){
              other: (#list){
              }
            }
          }, (list){
          }) }
      }
      entrypoint: ~(issue3638.full.used.output)
      used: (#struct){
        Routes: (#struct){
          route: (#struct){
            default: (#struct){
              spec: (#list){
                0: (#struct){
                  refs: (#list){
                    0: (string){ "default" }
                  }
                }
              }
            }
          }
        }
        input: (#struct){
          res1: (#struct){
            route: (#struct){
              default: (#struct){
                spec: (#list){
                  0: (#struct){
                    refs: (#list){
                      0: (string){ "default" }
                    }
                  }
                }
              }
            }
          }
        }
        output: (#list){
          0: (#struct){
            route: (#struct){
              default: (#struct){
                spec: (#list){
                  0: (#struct){
                    refs: (#list){
                      0: (string){ "default" }
                    }
                  }
                }
              }
            }
          }
        }
      }
    }
    reduced: (struct){
      input: (struct){
        k1: (struct){
          foo: (#struct){
            a: (int){ 1 }
          }
        }
      }
      out: (struct){
        foo: (#struct){
          a: (int){ 1 }
        }
      }
      #x: (#struct){ |(*(#struct){
          b: (int){ 2 }
        }, (#struct){
          a: (int){ int }
        }) }
    }
    compare: (struct){
      input: (struct){
        k1: (struct){
          foo: (#struct){
            a: (int){ 1 }
          }
        }
      }
      out: (struct){
        foo: (#struct){
          a: (int){ 1 }
        }
      }
      #x: (#struct){ |(*(#struct){
          b: (int){ 2 }
        }, (#struct){
          a: (int){ int }
        }) }
    }
  }
}
-- diff/-out/evalalpha<==>+out/eval --
diff old new
--- old
+++ new
@@ -1,34 +1,10 @@
 Errors:
 issue3670.a.not_int: field not allowed:
-    ./intpattern.cue:2:6
-    ./intpattern.cue:3:5
     ./intpattern.cue:4:5
 t1.c.z: field not allowed:
-    ./in.cue:15:6
-    ./in.cue:19:5
     ./in.cue:19:11
 t2.c.z: field not allowed:
-    ./in.cue:23:6
-    ./in.cue:27:5
     ./in.cue:27:11
-patternCycle.issue2109.p1.countries: cyclic pattern constraint:
-    ./issue2109.cue:11:15
-    ./issue2109.cue:10:13
-patternCycle.issue2109.p2.countries: cyclic pattern constraint:
-    ./issue2109.cue:15:15
-    ./issue2109.cue:17:13
-patternCycle.issue2109.p3.countries: cyclic pattern constraint:
-    ./issue2109.cue:21:15
-    ./issue2109.cue:22:13
-patternCycle.t1.p1.countries: cyclic pattern constraint:
-    ./issue2109.cue:27:15
-    ./issue2109.cue:26:13
-patternCycle.t1.p2.countries: cyclic pattern constraint:
-    ./issue2109.cue:33:15
-    ./issue2109.cue:32:13
-patternCycle.t1.p3.countries: cyclic pattern constraint:
-    ./issue2109.cue:37:15
-    ./issue2109.cue:38:13
 
 Result:
 (_|_){
@@ -41,16 +17,16 @@
     }
   }
   d: (struct){
-    foo: (struct){
-      a: (int){ 1 }
-      b: (int){ 1 }
-      name: (string){ "foo" }
-    }
     foobar: (struct){
       c: (int){ 2 }
       b: (int){ 1 }
       name: (string){ "foobar" }
     }
+    foo: (struct){
+      a: (int){ 1 }
+      b: (int){ 1 }
+      name: (string){ "foo" }
+    }
   }
   t1: (_|_){
     // [eval]
@@ -63,8 +39,6 @@
       // [eval]
       z: (_|_){
         // [eval] t1.c.z: field not allowed:
-        //     ./in.cue:15:6
-        //     ./in.cue:19:5
         //     ./in.cue:19:11
       }
     }
@@ -80,8 +54,6 @@
       // [eval]
       z: (_|_){
         // [eval] t2.c.z: field not allowed:
-        //     ./in.cue:23:6
-        //     ./in.cue:27:5
         //     ./in.cue:27:11
       }
     }
@@ -94,94 +66,56 @@
       // [eval]
       not_int: (_|_){
         // [eval] issue3670.a.not_int: field not allowed:
-        //     ./intpattern.cue:2:6
-        //     ./intpattern.cue:3:5
         //     ./intpattern.cue:4:5
       }
     }
   }
   dual: (_){ _ }
-  patternCycle: (_|_){
-    // [eval]
-    issue2109: (_|_){
-      // [eval]
-      p1: (_|_){
-        // [eval]
-        countries: (_|_){
-          // [eval] patternCycle.issue2109.p1.countries: cyclic pattern constraint:
-          //     ./issue2109.cue:11:15
-          //     ./issue2109.cue:10:13
-          0: (string){ "US" }
-          1: (string){ "GB" }
-          2: (string){ "AU" }
-        }
-        FlagsURLs: (struct){
-        }
-      }
-      p2: (_|_){
-        // [eval]
-        FlagsURLs: (struct){
-        }
-        countries: (_|_){
-          // [eval] patternCycle.issue2109.p2.countries: cyclic pattern constraint:
-          //     ./issue2109.cue:15:15
-          //     ./issue2109.cue:17:13
-          0: (_|_){// "US"
-          }
-          1: (_|_){// "GB"
-          }
-          2: (_|_){// "AU"
-          }
-        }
-      }
-      p3: (_|_){
-        // [eval]
-        FlagsURLs: (struct){
-        }
-        countries: (_|_){
-          // [eval] patternCycle.issue2109.p3.countries: cyclic pattern constraint:
-          //     ./issue2109.cue:21:15
-          //     ./issue2109.cue:22:13
-          0: (_|_){// "US"
-          }
-          1: (_|_){// "GB"
-          }
-          2: (_|_){// "AU"
-          }
-        }
-      }
-    }
-    t1: (_|_){
-      // [eval]
-      p1: (_|_){
-        // [eval]
-        countries: (_|_){
-          // [eval] patternCycle.t1.p1.countries: cyclic pattern constraint:
-          //     ./issue2109.cue:27:15
-          //     ./issue2109.cue:26:13
-        }
-        FlagsURLs: (struct){
-        }
-      }
-      p2: (_|_){
-        // [eval]
-        countries: (_|_){
-          // [eval] patternCycle.t1.p2.countries: cyclic pattern constraint:
-          //     ./issue2109.cue:33:15
-          //     ./issue2109.cue:32:13
-        }
-        FlagsURLs: (struct){
-        }
-      }
-      p3: (_|_){
-        // [eval]
-        FlagsURLs: (struct){
-        }
-        countries: (_|_){
-          // [eval] patternCycle.t1.p3.countries: cyclic pattern constraint:
-          //     ./issue2109.cue:37:15
-          //     ./issue2109.cue:38:13
-        }
+  patternCycle: (struct){
+    issue2109: (struct){
+      p1: (struct){
+        countries: (#list){
+          0: (string){ "US" }
+          1: (string){ "GB" }
+          2: (string){ "AU" }
+        }
+        FlagsURLs: (struct){
+        }
+      }
+      p2: (struct){
+        FlagsURLs: (struct){
+        }
+        countries: (#list){
+          0: (string){ "US" }
+          1: (string){ "GB" }
+          2: (string){ "AU" }
+        }
+      }
+      p3: (struct){
+        FlagsURLs: (struct){
+        }
+        countries: (#list){
+          0: (string){ "US" }
+          1: (string){ "GB" }
+          2: (string){ "AU" }
+        }
+      }
+    }
+    t1: (struct){
+      p1: (struct){
+        countries: (string){ |((string){ "US" }, (string){ "GB" }, (string){ "AU" }) }
+        FlagsURLs: (struct){
+        }
+      }
+      p2: (struct){
+        countries: (string){ |((string){ "US" }, (string){ "GB" }, (string){ "AU" }) }
+        FlagsURLs: (struct){
+        }
+      }
+      p3: (struct){
+        FlagsURLs: (struct){
+        }
+        countries: (string){ |((string){ "US" }, (string){ "GB" }, (string){ "AU" }) }
       }
     }
   }
@@ -206,20 +140,17 @@
         }
       }
       #Kubernetes: (#struct){
-        input: (#struct){
-          res1: (#struct){
-            route: (#struct){
-            }
-          }
-        }
-        output: (#list){
-          0: (#struct){
-            route: (#struct){
-            }
-          }
-        }
-        Routes: (#struct){
-          route: (#struct){
+        Routes: (#struct){
+          route: (#struct){
+          }
+        }
+        input: (#struct){
+          res1: ~(issue3638.full.#Kubernetes.Routes)
+        }
+        output: (#list){
+          0: (#struct){
+            route: (#struct){
+            }
           }
         }
       }
@@ -232,60 +163,8 @@
           }, (list){
           }) }
       }
-      entrypoint: (#list){
-        0: (struct){
-          route: (struct){
-            default: (struct){
-              spec: (#list){
-                0: (#struct){
-                  refs: (#list){
-                    0: (string){ "default" }
-                  }
-                }
-              }
-            }
-          }
-        }
-      }
+      entrypoint: ~(issue3638.full.used.output)
       used: (#struct){
-        input: (#struct){
-          res1: (#struct){
-            route: (#struct){
-              default: (#struct){
-                spec: (#list){
-                  0: (#struct){
-                    refs: (#list){
-                      0: (string){ "default" }
-                    }
-                  }
-                }
-              }
-            }
-          }
-        }
-        output: (#list){
-          0: (#struct){
-            route: (#struct){
-              default: (#struct){
-                spec: (list){ |(*(#list){
-                    0: (#struct){
-                      refs: (#list){
-                        0: (string){ "default" }
-                      }
-                      other: (#list){
-                      }
-                    }
-                  }, (#list){
-                    0: (#struct){
-                      refs: (#list){
-                        0: (string){ "default" }
-                      }
-                    }
-                  }) }
-              }
-            }
-          }
-        }
         Routes: (#struct){
           route: (#struct){
             default: (#struct){
@@ -299,6 +178,36 @@
             }
           }
         }
+        input: (#struct){
+          res1: (#struct){
+            route: (#struct){
+              default: (#struct){
+                spec: (#list){
+                  0: (#struct){
+                    refs: (#list){
+                      0: (string){ "default" }
+                    }
+                  }
+                }
+              }
+            }
+          }
+        }
+        output: (#list){
+          0: (#struct){
+            route: (#struct){
+              default: (#struct){
+                spec: (#list){
+                  0: (#struct){
+                    refs: (#list){
+                      0: (string){ "default" }
+                    }
+                  }
+                }
+              }
+            }
+          }
+        }
       }
     }
     reduced: (struct){
@@ -310,12 +219,9 @@
         }
       }
       out: (struct){
-        foo: (#struct){ |(*(#struct){
-            a: (int){ 1 }
-            b: (int){ 2 }
-          }, (#struct){
-            a: (int){ 1 }
-          }) }
+        foo: (#struct){
+          a: (int){ 1 }
+        }
       }
       #x: (#struct){ |(*(#struct){
           b: (int){ 2 }
@@ -332,12 +238,9 @@
         }
       }
       out: (struct){
-        foo: (#struct){ |(*(#struct){
-            a: (int){ 1 }
-            b: (int){ 2 }
-          }, (#struct){
-            a: (int){ 1 }
-          }) }
+        foo: (#struct){
+          a: (int){ 1 }
+        }
       }
       #x: (#struct){ |(*(#struct){
           b: (int){ 2 }
-- diff/todo/p3 --
Reordering of error messages.
-- diff/explanation --
Overall, the previous errors now passing is acceptable and consistent with
the behavior of the new evaluator.
issue3638: in V2, there was a spurious default marker to disambiguate
a disjunction that should have already been disambiguated.
In V3, the disjunction is properly disambiguated.
-- out/eval --
Errors:
issue3670.a.not_int: field not allowed:
    ./intpattern.cue:2:6
    ./intpattern.cue:3:5
    ./intpattern.cue:4:5
t1.c.z: field not allowed:
    ./in.cue:15:6
    ./in.cue:19:5
    ./in.cue:19:11
t2.c.z: field not allowed:
    ./in.cue:23:6
    ./in.cue:27:5
    ./in.cue:27:11
patternCycle.issue2109.p1.countries: cyclic pattern constraint:
    ./issue2109.cue:11:15
    ./issue2109.cue:10:13
patternCycle.issue2109.p2.countries: cyclic pattern constraint:
    ./issue2109.cue:15:15
    ./issue2109.cue:17:13
patternCycle.issue2109.p3.countries: cyclic pattern constraint:
    ./issue2109.cue:21:15
    ./issue2109.cue:22:13
patternCycle.t1.p1.countries: cyclic pattern constraint:
    ./issue2109.cue:27:15
    ./issue2109.cue:26:13
patternCycle.t1.p2.countries: cyclic pattern constraint:
    ./issue2109.cue:33:15
    ./issue2109.cue:32:13
patternCycle.t1.p3.countries: cyclic pattern constraint:
    ./issue2109.cue:37:15
    ./issue2109.cue:38:13

Result:
(_|_){
  // [eval]
  a: (struct){
    foo: (struct){
      a: (int){ 1 }
      b: (int){ 1 }
      name: (string){ "foo" }
    }
  }
  d: (struct){
    foo: (struct){
      a: (int){ 1 }
      b: (int){ 1 }
      name: (string){ "foo" }
    }
    foobar: (struct){
      c: (int){ 2 }
      b: (int){ 1 }
      name: (string){ "foobar" }
    }
  }
  t1: (_|_){
    // [eval]
    #a: (#struct){
    }
    b: (#struct){
      f: (int){ 4 }
    }
    c: (_|_){
      // [eval]
      z: (_|_){
        // [eval] t1.c.z: field not allowed:
        //     ./in.cue:15:6
        //     ./in.cue:19:5
        //     ./in.cue:19:11
      }
    }
  }
  t2: (_|_){
    // [eval]
    #a: (#struct){
    }
    b: (#struct){
      x: (int){ 4 }
    }
    c: (_|_){
      // [eval]
      z: (_|_){
        // [eval] t2.c.z: field not allowed:
        //     ./in.cue:23:6
        //     ./in.cue:27:5
        //     ./in.cue:27:11
      }
    }
  }
  issue3670: (_|_){
    // [eval]
    #X: (#struct){
    }
    a: (_|_){
      // [eval]
      not_int: (_|_){
        // [eval] issue3670.a.not_int: field not allowed:
        //     ./intpattern.cue:2:6
        //     ./intpattern.cue:3:5
        //     ./intpattern.cue:4:5
      }
    }
  }
  dual: (_){ _ }
  patternCycle: (_|_){
    // [eval]
    issue2109: (_|_){
      // [eval]
      p1: (_|_){
        // [eval]
        countries: (_|_){
          // [eval] patternCycle.issue2109.p1.countries: cyclic pattern constraint:
          //     ./issue2109.cue:11:15
          //     ./issue2109.cue:10:13
          0: (string){ "US" }
          1: (string){ "GB" }
          2: (string){ "AU" }
        }
        FlagsURLs: (struct){
        }
      }
      p2: (_|_){
        // [eval]
        FlagsURLs: (struct){
        }
        countries: (_|_){
          // [eval] patternCycle.issue2109.p2.countries: cyclic pattern constraint:
          //     ./issue2109.cue:15:15
          //     ./issue2109.cue:17:13
          0: (_|_){// "US"
          }
          1: (_|_){// "GB"
          }
          2: (_|_){// "AU"
          }
        }
      }
      p3: (_|_){
        // [eval]
        FlagsURLs: (struct){
        }
        countries: (_|_){
          // [eval] patternCycle.issue2109.p3.countries: cyclic pattern constraint:
          //     ./issue2109.cue:21:15
          //     ./issue2109.cue:22:13
          0: (_|_){// "US"
          }
          1: (_|_){// "GB"
          }
          2: (_|_){// "AU"
          }
        }
      }
    }
    t1: (_|_){
      // [eval]
      p1: (_|_){
        // [eval]
        countries: (_|_){
          // [eval] patternCycle.t1.p1.countries: cyclic pattern constraint:
          //     ./issue2109.cue:27:15
          //     ./issue2109.cue:26:13
        }
        FlagsURLs: (struct){
        }
      }
      p2: (_|_){
        // [eval]
        countries: (_|_){
          // [eval] patternCycle.t1.p2.countries: cyclic pattern constraint:
          //     ./issue2109.cue:33:15
          //     ./issue2109.cue:32:13
        }
        FlagsURLs: (struct){
        }
      }
      p3: (_|_){
        // [eval]
        FlagsURLs: (struct){
        }
        countries: (_|_){
          // [eval] patternCycle.t1.p3.countries: cyclic pattern constraint:
          //     ./issue2109.cue:37:15
          //     ./issue2109.cue:38:13
        }
      }
    }
  }
  issue3638: (struct){
    full: (struct){
      routes: (struct){
        default: (struct){
          spec: (#list){
            0: (struct){
              refs: (#list){
                0: (string){ "default" }
              }
            }
          }
        }
      }
      #Fields: (#struct){
        input: (_){ _ }
        output: (_|_){
          // [incomplete] issue3638.full.#Fields.output: cannot range over input (incomplete type _):
          //     ./multi.cue:10:21
        }
      }
      #Kubernetes: (#struct){
        input: (#struct){
          res1: (#struct){
            route: (#struct){
            }
          }
        }
        output: (#list){
          0: (#struct){
            route: (#struct){
            }
          }
        }
        Routes: (#struct){
          route: (#struct){
          }
        }
      }
      let HTTPROUTESPEC#1 = (struct){
        #x: (#list){ |(*(#list){
            0: (#struct){
              other: (#list){
              }
            }
          }, (list){
          }) }
      }
      entrypoint: (#list){
        0: (struct){
          route: (struct){
            default: (struct){
              spec: (#list){
                0: (#struct){
                  refs: (#list){
                    0: (string){ "default" }
                  }
                }
              }
            }
          }
        }
      }
      used: (#struct){
        input: (#struct){
          res1: (#struct){
            route: (#struct){
              default: (#struct){
                spec: (#list){
                  0: (#struct){
                    refs: (#list){
                      0: (string){ "default" }
                    }
                  }
                }
              }
            }
          }
        }
        output: (#list){
          0: (#struct){
            route: (#struct){
              default: (#struct){
                spec: (list){ |(*(#list){
                    0: (#struct){
                      refs: (#list){
                        0: (string){ "default" }
                      }
                      other: (#list){
                      }
                    }
                  }, (#list){
                    0: (#struct){
                      refs: (#list){
                        0: (string){ "default" }
                      }
                    }
                  }) }
              }
            }
          }
        }
        Routes: (#struct){
          route: (#struct){
            default: (#struct){
              spec: (#list){
                0: (#struct){
                  refs: (#list){
                    0: (string){ "default" }
                  }
                }
              }
            }
          }
        }
      }
    }
    reduced: (struct){
      input: (struct){
        k1: (struct){
          foo: (#struct){
            a: (int){ 1 }
          }
        }
      }
      out: (struct){
        foo: (#struct){ |(*(#struct){
            a: (int){ 1 }
            b: (int){ 2 }
          }, (#struct){
            a: (int){ 1 }
          }) }
      }
      #x: (#struct){ |(*(#struct){
          b: (int){ 2 }
        }, (#struct){
          a: (int){ int }
        }) }
    }
    compare: (struct){
      input: (struct){
        k1: (struct){
          foo: (#struct){
            a: (int){ 1 }
          }
        }
      }
      out: (struct){
        foo: (#struct){ |(*(#struct){
            a: (int){ 1 }
            b: (int){ 2 }
          }, (#struct){
            a: (int){ 1 }
          }) }
      }
      #x: (#struct){ |(*(#struct){
          b: (int){ 2 }
        }, (#struct){
          a: (int){ int }
        }) }
    }
  }
}
-- out/compile --
--- in.cue
{
  a: {
    foo: {
      a: 1
    }
    [=~"foo"]: {
      b: 1
      name: 〈1;-〉
    }
  }
  d: (〈0;a〉 & {
    foobar: {
      c: 2
    }
  })
  t1: {
    #a: {
      [(>"e" & <"z")]: int
    }
    b: (〈0;#a〉 & {
      f: 4
    })
    c: (〈0;#a〉 & {
      z: 4
    })
  }
  t2: {
    #a: {
      [("x"|"y")]: int
    }
    b: (〈0;#a〉 & {
      x: 4
    })
    c: (〈0;#a〉 & {
      z: 4
    })
  }
}
--- intpattern.cue
{
  issue3670: {
    #X: {
      [int]: string
    }
    a: 〈0;#X〉
    a: {
      not_int: "c"
    }
  }
  dual: {
    _
    [string]: _
    [int]: _
  }
}
--- issue2109.cue
{
  patternCycle: {
    issue2109: {
      p1: {
        countries: [
          "US",
          "GB",
          "AU",
        ]
        FlagsURLs: {
          [or(〈1;countries〉)]: string
        }
        〈0;FlagsURLs〉
      }
    }
  }
  patternCycle: {
    issue2109: {
      p2: {
        FlagsURLs: {
          [or(〈1;countries〉)]: string
        }
        〈0;FlagsURLs〉
        countries: [
          "US",
          "GB",
          "AU",
        ]
      }
    }
  }
  patternCycle: {
    issue2109: {
      p3: {
        〈0;FlagsURLs〉
        FlagsURLs: {
          [or(〈1;countries〉)]: string
        }
        countries: [
          "US",
          "GB",
          "AU",
        ]
      }
    }
  }
  patternCycle: {
    t1: {
      p1: {
        countries: ("US"|"GB"|"AU")
        FlagsURLs: {
          [〈1;countries〉]: string
        }
        〈0;FlagsURLs〉
      }
    }
  }
  patternCycle: {
    t1: {
      p2: {
        〈0;FlagsURLs〉
        countries: ("US"|"GB"|"AU")
        FlagsURLs: {
          [〈1;countries〉]: string
        }
      }
    }
  }
  patternCycle: {
    t1: {
      p3: {
        〈0;FlagsURLs〉
        FlagsURLs: {
          [〈1;countries〉]: string
        }
        countries: ("US"|"GB"|"AU")
      }
    }
  }
}
--- multi.cue
{
  issue3638: {
    full: {
      routes: {
        default: {}
      }
      routes: {
        [string]: {
          spec: [
            {
              refs: [
                {
                  "default"
                },
              ]
            },
          ]
        }
      }
      #Fields: {
        input: _
        output: [
          for _, x in 〈1;input〉 {
            〈1;x〉
          },
        ]
        ...
      }
      #Kubernetes: {
        (〈1;#Fields〉 & {
          Routes: {
            route: {
              [_]: {
                spec!: 〈5;let HTTPROUTESPEC#1〉.#x
              }
            }
          }
        })
        〈1;#Fields〉
        Routes: _
        input: {
          res1: 〈1;Routes〉
        }
      }
      let HTTPROUTESPEC#1 = {
        #x: ([
          ...{
            refs: [
              ...{
                string
              },
            ]
          },
        ]|*[
          {
            other: []
          },
        ])
      }
      entrypoint: 〈0;used〉.output
      used: (〈0;#Kubernetes〉 & {
        Routes: {
          route: 〈2;routes〉
        }
      })
    }
  }
  issue3638: {
    reduced: {
      input: {
        k1: {
          [string]: {
            a: 1
          }
        }
      }
      input: {
        k1: {
          foo: 〈2;#x〉
        }
      }
      out: {
        for _, x in 〈1;input〉 {
          〈1;x〉
        }
        for _, x in 〈1;input〉 {
          〈1;x〉
        }
      }
      #x: ({
        a: int
      }|*{
        b: 2
      })
    }
  }
  issue3638: {
    compare: {
      input: {
        k1: {
          foo: {
            a: 1
          }
        }
      }
      input: {
        k1: {
          foo: 〈2;#x〉
        }
      }
      out: {
        for _, x in 〈1;input〉 {
          〈1;x〉
        }
        for _, x in 〈1;input〉 {
          〈1;x〉
        }
      }
      #x: ({
        a: int
      }|*{
        b: 2
      })
    }
  }
}
