-- in.cue --
import (
	"encoding/json"
	"list"
	"struct"
)

// non-monotonic builtins must fail with an "incomplete" error if there
// is a possibility the constraint can get resolved by becoming more specific.
incompleteError1: {
	MyType: {
		kv: struct.MinFields(1)
	}

	foo: MyType & {
		kv: joel: "testing"
	}
}

incompleteError2: {
	MyType: {
		kv: [string]: string
		kv: struct.MinFields(1)
	}

	foo: MyType & {
		kv: joel: "testing"
	}
}

incompleteError3: {
	t: string
	t: json.Validate(string)
}

uniqueConstrains1: {
	t: string
	t: json.Validate(string)
	t: json.Validate(string)
}

uniqueConstrains2: {
	t: struct.MaxFields(1)
	t: struct.MaxFields(1)
}

violation: {
	#MyType: {
		kv: [string]: string
		kv: struct.MinFields(1)
	}

	foo: #MyType & {
		kv: joel: "testing"
		kv: tony: "testing"
	}
}

conjuncts: {
	kv: struct.MinFields(1)
	kv: struct.MaxFields(3)
}

// TODO: stripe off conflicting pairs
// conflicting: {
//     kv: struct.MinFields(3)
//     kv: struct.MaxFields(1)
// }

// Builtins with bool return that can be used as validator.

bareBuiltin: {
	a: json.Valid
	a: json.Valid
}

bareBuiltinCheck: {
	a: json.Valid
	a: "3"
}

builtinValidator: {
	a: json.Valid()
	a: json.Valid()
}

builtinValidatorCheck: {
	a: json.Valid()
	a: "3"
}

callOfCallToValidator: {
	a: json.Valid
	b: a()
	e: b() // not allowed
	e: "5"
}

validatorAsFunction: {
	a: json.Valid
	b: a("3")
	c: json.Valid("3")
}

issue2098: ok1: {
	_a: [1, ...]
	_a: list.MinItems(1)
	_a[0]
}

issue2098: incomplete1: {
	_a: [...]
	_a: list.MinItems(1)
	_a[0]
}

-- issue3418.cue --
issue3418: t1: "foo" & matchN(1, [1&2]) & matchN(1, [_])
issue3418: t2: "foo" & matchN(1, [_]) & matchN(1, [1&2])
issue3418: t3: {
	x: "foo"
	x: matchN(1, [_])
	x: matchN(1, [1&2])
}
issue3418: t4: {
	x: "foo"
	x: matchN(1, [1&2])
	x: matchN(1, [_])
}

-- issue3474.cue --
import "struct"

issue3474: structValidator: ok: {
	// Passes only after the comprehension is evaluated.
	A: struct.MinFields(1)
	A: {
		if true {B: true}
	}
}
issue3474: structValidator: failAfter: {
	// Passes only before the comprehension is evaluated.
	A: struct.MaxFields(1)
	A: {
		C: true
		if true {B: true}
	}
}
issue3474: structValidator: incomplete: {
	// Passes neither before nor after the comprehension is evaluated.
	A: struct.MinFields(1)
	A: {
		if true {}
	}
}
issue3474: structValidator: failClosed: {
	// Passes neither before nor after the comprehension is evaluated.
	#A: struct.MinFields(1)
	#A: {
		if true {}
	}
}


issue3474: topValidator: ok: {
	A: matchN(1, [>10])
	A: {
		if true {100}
	}
}
issue3474: topValidator: fail: {
	A: matchN(1, [>10])
	A: {
		if true {1}
	}
}
issue3474: topValidator: incomplete: {
	A: matchN(1, [>10])
	A: {
		if true {int}
	}
}
issue3474: topValidator: failType: {
	A: matchN(1, [>10])
	A: {
		if true {C: 1}
	}
}
-- validator_is_top.cue --
issue3639: {
	a: {#X} & #X
	a: b: 1
	#X: matchN(1, [{b: int}])
}
issue3661: {
	#X: matchN(1, [{ b!: int }])
	a: b: 1
	a: #X
	["a"]: #X
}
issue3678: {
	#X: matchN(1, [{
		a!: string
	}, {
		c!: string
	}])

	x: c: "c"
	
	y: #X
	y: x
	x: #X
}
-- out/eval/stats --
Leaks:  4
Freed:  177
Reused: 170
Allocs: 11
Retain: 23

Unifications: 181
Conjuncts:    327
Disjuncts:    202
-- out/evalalpha --
Errors:
issue3474.topValidator.failType.A: conflicting values >10 and {C:1} (mismatched types number and struct):
    ./issue3474.cue:53:5
    ./issue3474.cue:53:16
    ./issue3474.cue:54:5
callOfCallToValidator.e: cannot call previously called validator b:
    ./in.cue:94:5
issue3418.t1: invalid value "foo" (does not satisfy matchN): conflicting values 2 and 1:
    ./issue3418.cue:1:24
    ./issue3418.cue:1:16
    ./issue3418.cue:1:31
    ./issue3418.cue:1:35
    ./issue3418.cue:1:37
issue3418.t2: invalid value "foo" (does not satisfy matchN): conflicting values 2 and 1:
    ./issue3418.cue:2:41
    ./issue3418.cue:2:16
    ./issue3418.cue:2:48
    ./issue3418.cue:2:52
    ./issue3418.cue:2:54
issue3418.t3.x: invalid value "foo" (does not satisfy matchN): conflicting values 2 and 1:
    ./issue3418.cue:6:5
    ./issue3418.cue:4:5
    ./issue3418.cue:5:5
    ./issue3418.cue:6:12
    ./issue3418.cue:6:16
    ./issue3418.cue:6:18
issue3418.t4.x: invalid value "foo" (does not satisfy matchN): conflicting values 2 and 1:
    ./issue3418.cue:10:5
    ./issue3418.cue:9:5
    ./issue3418.cue:10:12
    ./issue3418.cue:10:16
    ./issue3418.cue:10:18
    ./issue3418.cue:11:5
issue3474.structValidator.failAfter.A: invalid value {C:true,B:true} (does not satisfy struct.MaxFields(1)): len(fields) > MaxFields(1) (2 > 1):
    ./issue3474.cue:12:5
    ./issue3474.cue:12:22
    ./issue3474.cue:13:5
issue3474.structValidator.failClosed.#A: invalid value {} (does not satisfy struct.MinFields(1)): len(fields) < MinFields(1) (0 < 1):
    ./issue3474.cue:27:6
    ./issue3474.cue:27:23
    ./issue3474.cue:28:6
issue3474.topValidator.fail.A: invalid value 1 (does not satisfy matchN): 0 matched, expected 1:
    ./issue3474.cue:41:5
    ./issue3474.cue:41:12
    ./issue3474.cue:42:5
    ./issue3474.cue:43:12
issue3474.topValidator.fail.A: invalid value 1 (out of bound >10):
    ./issue3474.cue:41:16
    ./issue3474.cue:43:12
issue3474.topValidator.failType.A: invalid value {C:1} (does not satisfy matchN): 0 matched, expected 1:
    ./issue3474.cue:53:5
    ./issue3474.cue:53:12
    ./issue3474.cue:54:5
issue3474.topValidator.failType.A: invalid operands {C:1} and 10 to '>' (type _|_ and int):
    ./issue3474.cue:53:16
    ./issue3474.cue:53:5
    ./issue3474.cue:53:17
    ./issue3474.cue:54:5

Result:
(_|_){
  // [eval]
  incompleteError1: (struct){
    MyType: (struct){
      kv: (struct){ struct.MinFields(1) }
    }
    foo: (struct){
      kv: (struct){
        joel: (string){ "testing" }
      }
    }
  }
  incompleteError2: (struct){
    MyType: (struct){
      kv: (_|_){
        // [incomplete] incompleteError2.MyType.kv: invalid value {} (does not satisfy struct.MinFields(1)): len(fields) < MinFields(1) (0 < 1):
        //     ./in.cue:22:7
        //     ./in.cue:21:7
        //     ./in.cue:22:24
      }
    }
    foo: (struct){
      kv: (struct){
        joel: (string){ "testing" }
      }
    }
  }
  incompleteError3: (struct){
    t: (string){ &("encoding/json".Validate(string), string) }
  }
  uniqueConstrains1: (struct){
    t: (string){ &("encoding/json".Validate(string), string) }
  }
  uniqueConstrains2: (struct){
    t: (struct){ struct.MaxFields(1) }
  }
  violation: (struct){
    #MyType: (#struct){
      kv: (_|_){
        // [incomplete] violation.#MyType.kv: invalid value {} (does not satisfy struct.MinFields(1)): len(fields) < MinFields(1) (0 < 1):
        //     ./in.cue:49:7
        //     ./in.cue:48:7
        //     ./in.cue:49:24
      }
    }
    foo: (#struct){
      kv: (#struct){
        joel: (string){ "testing" }
        tony: (string){ "testing" }
      }
    }
  }
  conjuncts: (struct){
    kv: (struct){ &(struct.MinFields(1), struct.MaxFields(3)) }
  }
  bareBuiltin: (struct){
    a: ((string|bytes)){ "encoding/json".Valid() }
  }
  bareBuiltinCheck: (struct){
    a: (string){ "3" }
  }
  builtinValidator: (struct){
    a: ((string|bytes)){ "encoding/json".Valid() }
  }
  builtinValidatorCheck: (struct){
    a: (string){ "3" }
  }
  callOfCallToValidator: (_|_){
    // [eval]
    a: ((string|bytes)){ "encoding/json".Valid() }
    b: ((string|bytes)){ "encoding/json".Valid() }
    e: (_|_){
      // [eval] callOfCallToValidator.e: cannot call previously called validator b:
      //     ./in.cue:94:5
    }
  }
  validatorAsFunction: (struct){
    a: ((string|bytes)){ "encoding/json".Valid() }
    b: (bool){ true }
    c: (bool){ true }
  }
  issue2098: (struct){
    ok1: (int){
      1
      _a: (list){
        0: (int){ 1 }
      }
    }
    incomplete1: (_|_){
      // [incomplete] issue2098.incomplete1: index out of range [0] with length 1:
      //     ./in.cue:113:5
      _a: (_|_){
        // [incomplete] issue2098.incomplete1._a: invalid value [] (does not satisfy list.MinItems(1)): len(list) < MinItems(1) (0 < 1):
        //     ./in.cue:112:6
        //     ./in.cue:111:6
        //     ./in.cue:112:20
      }
    }
  }
  issue3418: (_|_){
    // [eval]
    t1: (_|_){
      // [eval] issue3418.t1: invalid value "foo" (does not satisfy matchN): conflicting values 2 and 1:
      //     ./issue3418.cue:1:24
      //     ./issue3418.cue:1:16
      //     ./issue3418.cue:1:31
      //     ./issue3418.cue:1:35
      //     ./issue3418.cue:1:37
    }
    t2: (_|_){
      // [eval] issue3418.t2: invalid value "foo" (does not satisfy matchN): conflicting values 2 and 1:
      //     ./issue3418.cue:2:41
      //     ./issue3418.cue:2:16
      //     ./issue3418.cue:2:48
      //     ./issue3418.cue:2:52
      //     ./issue3418.cue:2:54
    }
    t3: (_|_){
      // [eval]
      x: (_|_){
        // [eval] issue3418.t3.x: invalid value "foo" (does not satisfy matchN): conflicting values 2 and 1:
        //     ./issue3418.cue:6:5
        //     ./issue3418.cue:4:5
        //     ./issue3418.cue:5:5
        //     ./issue3418.cue:6:12
        //     ./issue3418.cue:6:16
        //     ./issue3418.cue:6:18
      }
    }
    t4: (_|_){
      // [eval]
      x: (_|_){
        // [eval] issue3418.t4.x: invalid value "foo" (does not satisfy matchN): conflicting values 2 and 1:
        //     ./issue3418.cue:10:5
        //     ./issue3418.cue:9:5
        //     ./issue3418.cue:10:12
        //     ./issue3418.cue:10:16
        //     ./issue3418.cue:10:18
        //     ./issue3418.cue:11:5
      }
    }
  }
  issue3474: (_|_){
    // [eval]
    structValidator: (_|_){
      // [eval]
      ok: (struct){
        A: (struct){
          B: (bool){ true }
        }
      }
      failAfter: (_|_){
        // [eval]
        A: (_|_){
          // [eval] issue3474.structValidator.failAfter.A: invalid value {C:true,B:true} (does not satisfy struct.MaxFields(1)): len(fields) > MaxFields(1) (2 > 1):
          //     ./issue3474.cue:12:5
          //     ./issue3474.cue:12:22
          //     ./issue3474.cue:13:5
          C: (bool){ true }
          B: (bool){ true }
        }
      }
      incomplete: (struct){
        A: (_|_){
          // [incomplete] issue3474.structValidator.incomplete.A: invalid value {} (does not satisfy struct.MinFields(1)): len(fields) < MinFields(1) (0 < 1):
          //     ./issue3474.cue:20:5
          //     ./issue3474.cue:20:22
          //     ./issue3474.cue:21:5
        }
      }
      failClosed: (_|_){
        // [eval]
        #A: (_|_){
          // [eval] issue3474.structValidator.failClosed.#A: invalid value {} (does not satisfy struct.MinFields(1)): len(fields) < MinFields(1) (0 < 1):
          //     ./issue3474.cue:27:6
          //     ./issue3474.cue:27:23
          //     ./issue3474.cue:28:6
        }
      }
    }
    topValidator: (_|_){
      // [eval]
      ok: (struct){
        A: (int){ 100 }
      }
      fail: (_|_){
        // [eval]
        A: (_|_){
          // [eval] issue3474.topValidator.fail.A: invalid value 1 (does not satisfy matchN): 0 matched, expected 1:
          //     ./issue3474.cue:41:5
          //     ./issue3474.cue:41:12
          //     ./issue3474.cue:42:5
          //     ./issue3474.cue:43:12
          // issue3474.topValidator.fail.A: invalid value 1 (out of bound >10):
          //     ./issue3474.cue:41:16
          //     ./issue3474.cue:43:12
        }
      }
      incomplete: (struct){
        A: (int){ &(matchN(1, (#list){
            0: (_|_){// >10
            }
          }), int) }
      }
      failType: (_|_){
        // [eval]
        A: (_|_){
          // [eval] issue3474.topValidator.failType.A: conflicting values >10 and {C:1} (mismatched types number and struct):
          //     ./issue3474.cue:53:5
          //     ./issue3474.cue:53:16
          //     ./issue3474.cue:54:5
          // issue3474.topValidator.failType.A: invalid value {C:1} (does not satisfy matchN): 0 matched, expected 1:
          //     ./issue3474.cue:53:5
          //     ./issue3474.cue:53:12
          //     ./issue3474.cue:54:5
          // issue3474.topValidator.failType.A: invalid operands {C:1} and 10 to '>' (type _|_ and int):
          //     ./issue3474.cue:53:16
          //     ./issue3474.cue:53:5
          //     ./issue3474.cue:53:17
          //     ./issue3474.cue:54:5
          C: (int){ 1 }
        }
      }
    }
  }
  issue3639: (struct){
    a: (#struct){
      b: (int){ 1 }
    }
    #X: (_){ matchN(1, (#list){
        0: (_|_){// {
          //   b: int
          // }
        }
      }) }
  }
  issue3661: (struct){
    #X: (_){ matchN(1, (#list){
        0: (_|_){// {
          //   b!: int
          // }
        }
      }) }
    a: (#struct){
      b: (int){ 1 }
    }
  }
  issue3678: (struct){
    #X: (_){ matchN(1, (#list){
        0: (_|_){// {
          //   a!: string
          // }
        }
        1: (_|_){// {
          //   c!: string
          // }
        }
      }) }
    x: (#struct){
      c: (string){ "c" }
    }
    y: (#struct){
      c: (string){ "c" }
    }
  }
}
-- diff/-out/evalalpha<==>+out/eval --
diff old new
--- old
+++ new
@@ -31,7 +31,7 @@
     ./issue3418.cue:10:16
     ./issue3418.cue:10:18
     ./issue3418.cue:11:5
-issue3474.structValidator.failAfter.A: invalid value {C:true,B*:if true true} (does not satisfy struct.MaxFields(1)): len(fields) > MaxFields(1) (2 > 1):
+issue3474.structValidator.failAfter.A: invalid value {C:true,B:true} (does not satisfy struct.MaxFields(1)): len(fields) > MaxFields(1) (2 > 1):
     ./issue3474.cue:12:5
     ./issue3474.cue:12:22
     ./issue3474.cue:13:5
@@ -51,6 +51,11 @@
     ./issue3474.cue:53:5
     ./issue3474.cue:53:12
     ./issue3474.cue:54:5
+issue3474.topValidator.failType.A: invalid operands {C:1} and 10 to '>' (type _|_ and int):
+    ./issue3474.cue:53:16
+    ./issue3474.cue:53:5
+    ./issue3474.cue:53:17
+    ./issue3474.cue:54:5
 
 Result:
 (_|_){
@@ -142,10 +147,8 @@
       }
     }
     incomplete1: (_|_){
-      // [incomplete] issue2098.incomplete1._a: invalid value [] (does not satisfy list.MinItems(1)): len(list) < MinItems(1) (0 < 1):
-      //     ./in.cue:112:6
-      //     ./in.cue:111:6
-      //     ./in.cue:112:20
+      // [incomplete] issue2098.incomplete1: index out of range [0] with length 1:
+      //     ./in.cue:113:5
       _a: (_|_){
         // [incomplete] issue2098.incomplete1._a: invalid value [] (does not satisfy list.MinItems(1)): len(list) < MinItems(1) (0 < 1):
         //     ./in.cue:112:6
@@ -209,7 +212,7 @@
       failAfter: (_|_){
         // [eval]
         A: (_|_){
-          // [eval] issue3474.structValidator.failAfter.A: invalid value {C:true,B*:if true true} (does not satisfy struct.MaxFields(1)): len(fields) > MaxFields(1) (2 > 1):
+          // [eval] issue3474.structValidator.failAfter.A: invalid value {C:true,B:true} (does not satisfy struct.MaxFields(1)): len(fields) > MaxFields(1) (2 > 1):
           //     ./issue3474.cue:12:5
           //     ./issue3474.cue:12:22
           //     ./issue3474.cue:13:5
@@ -270,6 +273,11 @@
           //     ./issue3474.cue:53:5
           //     ./issue3474.cue:53:12
           //     ./issue3474.cue:54:5
+          // issue3474.topValidator.failType.A: invalid operands {C:1} and 10 to '>' (type _|_ and int):
+          //     ./issue3474.cue:53:16
+          //     ./issue3474.cue:53:5
+          //     ./issue3474.cue:53:17
+          //     ./issue3474.cue:54:5
           C: (int){ 1 }
         }
       }
@@ -276,7 +284,7 @@
     }
   }
   issue3639: (struct){
-    a: (struct){
+    a: (#struct){
       b: (int){ 1 }
     }
     #X: (_){ matchN(1, (#list){
@@ -293,7 +301,7 @@
           // }
         }
       }) }
-    a: (struct){
+    a: (#struct){
       b: (int){ 1 }
     }
   }
@@ -308,10 +316,10 @@
           // }
         }
       }) }
-    x: (struct){
-      c: (string){ "c" }
-    }
-    y: (struct){
+    x: (#struct){
+      c: (string){ "c" }
+    }
+    y: (#struct){
       c: (string){ "c" }
     }
   }
-- out/eval --
Errors:
issue3474.topValidator.failType.A: conflicting values >10 and {C:1} (mismatched types number and struct):
    ./issue3474.cue:53:5
    ./issue3474.cue:53:16
    ./issue3474.cue:54:5
callOfCallToValidator.e: cannot call previously called validator b:
    ./in.cue:94:5
issue3418.t1: invalid value "foo" (does not satisfy matchN): conflicting values 2 and 1:
    ./issue3418.cue:1:24
    ./issue3418.cue:1:16
    ./issue3418.cue:1:31
    ./issue3418.cue:1:35
    ./issue3418.cue:1:37
issue3418.t2: invalid value "foo" (does not satisfy matchN): conflicting values 2 and 1:
    ./issue3418.cue:2:41
    ./issue3418.cue:2:16
    ./issue3418.cue:2:48
    ./issue3418.cue:2:52
    ./issue3418.cue:2:54
issue3418.t3.x: invalid value "foo" (does not satisfy matchN): conflicting values 2 and 1:
    ./issue3418.cue:6:5
    ./issue3418.cue:4:5
    ./issue3418.cue:5:5
    ./issue3418.cue:6:12
    ./issue3418.cue:6:16
    ./issue3418.cue:6:18
issue3418.t4.x: invalid value "foo" (does not satisfy matchN): conflicting values 2 and 1:
    ./issue3418.cue:10:5
    ./issue3418.cue:9:5
    ./issue3418.cue:10:12
    ./issue3418.cue:10:16
    ./issue3418.cue:10:18
    ./issue3418.cue:11:5
issue3474.structValidator.failAfter.A: invalid value {C:true,B*:if true true} (does not satisfy struct.MaxFields(1)): len(fields) > MaxFields(1) (2 > 1):
    ./issue3474.cue:12:5
    ./issue3474.cue:12:22
    ./issue3474.cue:13:5
issue3474.structValidator.failClosed.#A: invalid value {} (does not satisfy struct.MinFields(1)): len(fields) < MinFields(1) (0 < 1):
    ./issue3474.cue:27:6
    ./issue3474.cue:27:23
    ./issue3474.cue:28:6
issue3474.topValidator.fail.A: invalid value 1 (does not satisfy matchN): 0 matched, expected 1:
    ./issue3474.cue:41:5
    ./issue3474.cue:41:12
    ./issue3474.cue:42:5
    ./issue3474.cue:43:12
issue3474.topValidator.fail.A: invalid value 1 (out of bound >10):
    ./issue3474.cue:41:16
    ./issue3474.cue:43:12
issue3474.topValidator.failType.A: invalid value {C:1} (does not satisfy matchN): 0 matched, expected 1:
    ./issue3474.cue:53:5
    ./issue3474.cue:53:12
    ./issue3474.cue:54:5

Result:
(_|_){
  // [eval]
  incompleteError1: (struct){
    MyType: (struct){
      kv: (struct){ struct.MinFields(1) }
    }
    foo: (struct){
      kv: (struct){
        joel: (string){ "testing" }
      }
    }
  }
  incompleteError2: (struct){
    MyType: (struct){
      kv: (_|_){
        // [incomplete] incompleteError2.MyType.kv: invalid value {} (does not satisfy struct.MinFields(1)): len(fields) < MinFields(1) (0 < 1):
        //     ./in.cue:22:7
        //     ./in.cue:21:7
        //     ./in.cue:22:24
      }
    }
    foo: (struct){
      kv: (struct){
        joel: (string){ "testing" }
      }
    }
  }
  incompleteError3: (struct){
    t: (string){ &("encoding/json".Validate(string), string) }
  }
  uniqueConstrains1: (struct){
    t: (string){ &("encoding/json".Validate(string), string) }
  }
  uniqueConstrains2: (struct){
    t: (struct){ struct.MaxFields(1) }
  }
  violation: (struct){
    #MyType: (#struct){
      kv: (_|_){
        // [incomplete] violation.#MyType.kv: invalid value {} (does not satisfy struct.MinFields(1)): len(fields) < MinFields(1) (0 < 1):
        //     ./in.cue:49:7
        //     ./in.cue:48:7
        //     ./in.cue:49:24
      }
    }
    foo: (#struct){
      kv: (#struct){
        joel: (string){ "testing" }
        tony: (string){ "testing" }
      }
    }
  }
  conjuncts: (struct){
    kv: (struct){ &(struct.MinFields(1), struct.MaxFields(3)) }
  }
  bareBuiltin: (struct){
    a: ((string|bytes)){ "encoding/json".Valid() }
  }
  bareBuiltinCheck: (struct){
    a: (string){ "3" }
  }
  builtinValidator: (struct){
    a: ((string|bytes)){ "encoding/json".Valid() }
  }
  builtinValidatorCheck: (struct){
    a: (string){ "3" }
  }
  callOfCallToValidator: (_|_){
    // [eval]
    a: ((string|bytes)){ "encoding/json".Valid() }
    b: ((string|bytes)){ "encoding/json".Valid() }
    e: (_|_){
      // [eval] callOfCallToValidator.e: cannot call previously called validator b:
      //     ./in.cue:94:5
    }
  }
  validatorAsFunction: (struct){
    a: ((string|bytes)){ "encoding/json".Valid() }
    b: (bool){ true }
    c: (bool){ true }
  }
  issue2098: (struct){
    ok1: (int){
      1
      _a: (list){
        0: (int){ 1 }
      }
    }
    incomplete1: (_|_){
      // [incomplete] issue2098.incomplete1._a: invalid value [] (does not satisfy list.MinItems(1)): len(list) < MinItems(1) (0 < 1):
      //     ./in.cue:112:6
      //     ./in.cue:111:6
      //     ./in.cue:112:20
      _a: (_|_){
        // [incomplete] issue2098.incomplete1._a: invalid value [] (does not satisfy list.MinItems(1)): len(list) < MinItems(1) (0 < 1):
        //     ./in.cue:112:6
        //     ./in.cue:111:6
        //     ./in.cue:112:20
      }
    }
  }
  issue3418: (_|_){
    // [eval]
    t1: (_|_){
      // [eval] issue3418.t1: invalid value "foo" (does not satisfy matchN): conflicting values 2 and 1:
      //     ./issue3418.cue:1:24
      //     ./issue3418.cue:1:16
      //     ./issue3418.cue:1:31
      //     ./issue3418.cue:1:35
      //     ./issue3418.cue:1:37
    }
    t2: (_|_){
      // [eval] issue3418.t2: invalid value "foo" (does not satisfy matchN): conflicting values 2 and 1:
      //     ./issue3418.cue:2:41
      //     ./issue3418.cue:2:16
      //     ./issue3418.cue:2:48
      //     ./issue3418.cue:2:52
      //     ./issue3418.cue:2:54
    }
    t3: (_|_){
      // [eval]
      x: (_|_){
        // [eval] issue3418.t3.x: invalid value "foo" (does not satisfy matchN): conflicting values 2 and 1:
        //     ./issue3418.cue:6:5
        //     ./issue3418.cue:4:5
        //     ./issue3418.cue:5:5
        //     ./issue3418.cue:6:12
        //     ./issue3418.cue:6:16
        //     ./issue3418.cue:6:18
      }
    }
    t4: (_|_){
      // [eval]
      x: (_|_){
        // [eval] issue3418.t4.x: invalid value "foo" (does not satisfy matchN): conflicting values 2 and 1:
        //     ./issue3418.cue:10:5
        //     ./issue3418.cue:9:5
        //     ./issue3418.cue:10:12
        //     ./issue3418.cue:10:16
        //     ./issue3418.cue:10:18
        //     ./issue3418.cue:11:5
      }
    }
  }
  issue3474: (_|_){
    // [eval]
    structValidator: (_|_){
      // [eval]
      ok: (struct){
        A: (struct){
          B: (bool){ true }
        }
      }
      failAfter: (_|_){
        // [eval]
        A: (_|_){
          // [eval] issue3474.structValidator.failAfter.A: invalid value {C:true,B*:if true true} (does not satisfy struct.MaxFields(1)): len(fields) > MaxFields(1) (2 > 1):
          //     ./issue3474.cue:12:5
          //     ./issue3474.cue:12:22
          //     ./issue3474.cue:13:5
          C: (bool){ true }
          B: (bool){ true }
        }
      }
      incomplete: (struct){
        A: (_|_){
          // [incomplete] issue3474.structValidator.incomplete.A: invalid value {} (does not satisfy struct.MinFields(1)): len(fields) < MinFields(1) (0 < 1):
          //     ./issue3474.cue:20:5
          //     ./issue3474.cue:20:22
          //     ./issue3474.cue:21:5
        }
      }
      failClosed: (_|_){
        // [eval]
        #A: (_|_){
          // [eval] issue3474.structValidator.failClosed.#A: invalid value {} (does not satisfy struct.MinFields(1)): len(fields) < MinFields(1) (0 < 1):
          //     ./issue3474.cue:27:6
          //     ./issue3474.cue:27:23
          //     ./issue3474.cue:28:6
        }
      }
    }
    topValidator: (_|_){
      // [eval]
      ok: (struct){
        A: (int){ 100 }
      }
      fail: (_|_){
        // [eval]
        A: (_|_){
          // [eval] issue3474.topValidator.fail.A: invalid value 1 (does not satisfy matchN): 0 matched, expected 1:
          //     ./issue3474.cue:41:5
          //     ./issue3474.cue:41:12
          //     ./issue3474.cue:42:5
          //     ./issue3474.cue:43:12
          // issue3474.topValidator.fail.A: invalid value 1 (out of bound >10):
          //     ./issue3474.cue:41:16
          //     ./issue3474.cue:43:12
        }
      }
      incomplete: (struct){
        A: (int){ &(matchN(1, (#list){
            0: (_|_){// >10
            }
          }), int) }
      }
      failType: (_|_){
        // [eval]
        A: (_|_){
          // [eval] issue3474.topValidator.failType.A: conflicting values >10 and {C:1} (mismatched types number and struct):
          //     ./issue3474.cue:53:5
          //     ./issue3474.cue:53:16
          //     ./issue3474.cue:54:5
          // issue3474.topValidator.failType.A: invalid value {C:1} (does not satisfy matchN): 0 matched, expected 1:
          //     ./issue3474.cue:53:5
          //     ./issue3474.cue:53:12
          //     ./issue3474.cue:54:5
          C: (int){ 1 }
        }
      }
    }
  }
  issue3639: (struct){
    a: (struct){
      b: (int){ 1 }
    }
    #X: (_){ matchN(1, (#list){
        0: (_|_){// {
          //   b: int
          // }
        }
      }) }
  }
  issue3661: (struct){
    #X: (_){ matchN(1, (#list){
        0: (_|_){// {
          //   b!: int
          // }
        }
      }) }
    a: (struct){
      b: (int){ 1 }
    }
  }
  issue3678: (struct){
    #X: (_){ matchN(1, (#list){
        0: (_|_){// {
          //   a!: string
          // }
        }
        1: (_|_){// {
          //   c!: string
          // }
        }
      }) }
    x: (struct){
      c: (string){ "c" }
    }
    y: (struct){
      c: (string){ "c" }
    }
  }
}
-- out/compile --
--- in.cue
{
  incompleteError1: {
    MyType: {
      kv: 〈import;struct〉.MinFields(1)
    }
    foo: (〈0;MyType〉 & {
      kv: {
        joel: "testing"
      }
    })
  }
  incompleteError2: {
    MyType: {
      kv: {
        [string]: string
      }
      kv: 〈import;struct〉.MinFields(1)
    }
    foo: (〈0;MyType〉 & {
      kv: {
        joel: "testing"
      }
    })
  }
  incompleteError3: {
    t: string
    t: 〈import;"encoding/json"〉.Validate(string)
  }
  uniqueConstrains1: {
    t: string
    t: 〈import;"encoding/json"〉.Validate(string)
    t: 〈import;"encoding/json"〉.Validate(string)
  }
  uniqueConstrains2: {
    t: 〈import;struct〉.MaxFields(1)
    t: 〈import;struct〉.MaxFields(1)
  }
  violation: {
    #MyType: {
      kv: {
        [string]: string
      }
      kv: 〈import;struct〉.MinFields(1)
    }
    foo: (〈0;#MyType〉 & {
      kv: {
        joel: "testing"
      }
      kv: {
        tony: "testing"
      }
    })
  }
  conjuncts: {
    kv: 〈import;struct〉.MinFields(1)
    kv: 〈import;struct〉.MaxFields(3)
  }
  bareBuiltin: {
    a: 〈import;"encoding/json"〉.Valid
    a: 〈import;"encoding/json"〉.Valid
  }
  bareBuiltinCheck: {
    a: 〈import;"encoding/json"〉.Valid
    a: "3"
  }
  builtinValidator: {
    a: 〈import;"encoding/json"〉.Valid()
    a: 〈import;"encoding/json"〉.Valid()
  }
  builtinValidatorCheck: {
    a: 〈import;"encoding/json"〉.Valid()
    a: "3"
  }
  callOfCallToValidator: {
    a: 〈import;"encoding/json"〉.Valid
    b: 〈0;a〉()
    e: 〈0;b〉()
    e: "5"
  }
  validatorAsFunction: {
    a: 〈import;"encoding/json"〉.Valid
    b: 〈0;a〉("3")
    c: 〈import;"encoding/json"〉.Valid("3")
  }
  issue2098: {
    ok1: {
      _a: [
        1,
        ...,
      ]
      _a: 〈import;list〉.MinItems(1)
      〈0;_a〉[0]
    }
  }
  issue2098: {
    incomplete1: {
      _a: [
        ...,
      ]
      _a: 〈import;list〉.MinItems(1)
      〈0;_a〉[0]
    }
  }
}
--- issue3418.cue
{
  issue3418: {
    t1: (("foo" & matchN(1, [
      (1 & 2),
    ])) & matchN(1, [
      _,
    ]))
  }
  issue3418: {
    t2: (("foo" & matchN(1, [
      _,
    ])) & matchN(1, [
      (1 & 2),
    ]))
  }
  issue3418: {
    t3: {
      x: "foo"
      x: matchN(1, [
        _,
      ])
      x: matchN(1, [
        (1 & 2),
      ])
    }
  }
  issue3418: {
    t4: {
      x: "foo"
      x: matchN(1, [
        (1 & 2),
      ])
      x: matchN(1, [
        _,
      ])
    }
  }
}
--- issue3474.cue
{
  issue3474: {
    structValidator: {
      ok: {
        A: 〈import;struct〉.MinFields(1)
        A: {
          if true {
            B: true
          }
        }
      }
    }
  }
  issue3474: {
    structValidator: {
      failAfter: {
        A: 〈import;struct〉.MaxFields(1)
        A: {
          C: true
          if true {
            B: true
          }
        }
      }
    }
  }
  issue3474: {
    structValidator: {
      incomplete: {
        A: 〈import;struct〉.MinFields(1)
        A: {
          if true {}
        }
      }
    }
  }
  issue3474: {
    structValidator: {
      failClosed: {
        #A: 〈import;struct〉.MinFields(1)
        #A: {
          if true {}
        }
      }
    }
  }
  issue3474: {
    topValidator: {
      ok: {
        A: matchN(1, [
          >10,
        ])
        A: {
          if true {
            100
          }
        }
      }
    }
  }
  issue3474: {
    topValidator: {
      fail: {
        A: matchN(1, [
          >10,
        ])
        A: {
          if true {
            1
          }
        }
      }
    }
  }
  issue3474: {
    topValidator: {
      incomplete: {
        A: matchN(1, [
          >10,
        ])
        A: {
          if true {
            int
          }
        }
      }
    }
  }
  issue3474: {
    topValidator: {
      failType: {
        A: matchN(1, [
          >10,
        ])
        A: {
          if true {
            C: 1
          }
        }
      }
    }
  }
}
--- validator_is_top.cue
{
  issue3639: {
    a: ({
      〈1;#X〉
    } & 〈0;#X〉)
    a: {
      b: 1
    }
    #X: matchN(1, [
      {
        b: int
      },
    ])
  }
  issue3661: {
    #X: matchN(1, [
      {
        b!: int
      },
    ])
    a: {
      b: 1
    }
    a: 〈0;#X〉
    ["a"]: 〈0;#X〉
  }
  issue3678: {
    #X: matchN(1, [
      {
        a!: string
      },
      {
        c!: string
      },
    ])
    x: {
      c: "c"
    }
    y: 〈0;#X〉
    y: 〈0;x〉
    x: 〈0;#X〉
  }
}
