-- in.cue --
self: {
	// This is an incomplete error, as it may succeed when the user
	// explicitly specifies a value for fail.a.b.
	fail: {
		a: {
			if a.b == _|_ {
				b: 1
			}
		}
	}

	// This is an incomplete error, as it may succeed when the user
	// explicitly specifies a value for a.b.
	isConcreteFail: t1:{
		a: {
			if a.b == _|_ {
				b: 1
			}
			b: int
		}
	}

	isConcreteFail: t2:{
		a: {
			if a.b == _|_ {
				b: 1
			}
			b?: int
		}
	}

	// This is an incomplete error, as it may succeed when the user
	// explicitly specifies a value for a.b.
	// TODO: new builtin semantics.
	//     if isconcrete(a.b)  -->> cyclic error evaluating isconcrete.
	//     if isdefined(a.b)   -->> evaluate to true as a.b is int, result is 1
	//     if !isdefined(a.b)  -->> evaluate to false, a.b remains int
	isNotConcrete: t1: {
		a: {
			if a.b != _|_ {
				b: 1
			}
			b: int
		}
	}
	isNotConcrete: t2: {
		a: {
			if a.b != _|_ {
				b: 1
			}
			b?: int
		}
	}

}

-- mutual.cue --
mutual: {
	noConflicts: {
		a: {if b.foo == _|_ {new: ""}}
		b: {if a.bar == _|_ {new: ""}}
	}

	mutualCycleFail: {
		b: {if a.bar == _|_ {foo: ""}}
		a: {if b.foo == _|_ {bar: ""}}
	}

	brokenCycleSuccess: {
		a: { if b.foo == _|_ { foo: "" } }
		b: { if a.bar == _|_ { bar: "" } }
		a: bar: ""
	}

	allowOneDirectionalDependency: {
		p1: {
			a: { if b.foo == _|_ { bar: "" } } // added
			b: { if a.bar == _|_ { new: "" } } // not added
		}
		p2: {
			a: { if b.foo == _|_ { new: "" } }
			b: { if a.bar == _|_ { foo: "" } }
		}
	}

	oneDirectionalBrokenConflictSuccess: p1: {
		b: foo: ""
		a: { if b.foo == _|_ { bar: "" } }
		b: { if a.bar == _|_ { new: "" } }
	}
	oneDirectionalBrokenConflictSuccess: p2: {
		a: { if b.foo == _|_ { bar: "" } }
		b: foo: ""
		b: { if a.bar == _|_ { new: "" } }
	}
	oneDirectionalBrokenConflictSuccess: p3: {
		a: { if b.foo == _|_ { bar: "" } }
		b: { if a.bar == _|_ { new: "" } }
		b: foo: ""
	}
	oneDirectionalBrokenConflictSuccess: p4: {
		b: foo: ""
		b: { if a.bar == _|_ { new: "" } }
		a: { if b.foo == _|_ { bar: "" } }
	}
	oneDirectionalBrokenConflictSuccess: p5: {
		b: { if a.bar == _|_ { new: "" } }
		b: foo: ""
		a: { if b.foo == _|_ { bar: "" } }
	}
	oneDirectionalBrokenConflictSuccess: p6: {
		b: { if a.bar == _|_ { new: "" } }
		a: { if b.foo == _|_ { bar: "" } }
		b: foo: ""
	}
}

-- mutualsamestruct.cue --
sameStruct: {
	chainSuccess: a: {
		raises?: {}
		if raises == _|_ {
		ret: a: 1
		}
		ret?: {}
		if ret != _|_ {
		foo: a: 1
		}
	}

	chainSuccess: b: {
		if ret != _|_ {
		foo: a: 1
		}
		raises?: {}
		if raises == _|_ {
		ret: a: 1
		}
		ret?: {}
	}

	cycleFail: t1: p1: {
		raises?: {}
		if raises == _|_ {
			ret: a: 1
		}
		ret?: {}
		if ret != _|_ {
			raises: a: 1
		}
	}

	cycleFail: t1: p2: {
		ret?: {}
		if ret != _|_ {
			raises: a: 1
		}
		raises?: {}
		if raises == _|_ {
			ret: a: 1
		}
	}

	// This test should fail with a cycle error. Even though raises and ret are
	// both known to be defined, comparison against bottom requires that the
	// structs be recursively checked for errors. We disallow that here, because
	// the structs mutually depend on each other.
	// TODO: consider allowing a specific postCheck for determining if an arc
	// is erroneous.
	cycleFail: t2: p1: {
		raises: {}
		if raises == _|_ {
			ret: a: 1
		}
		ret: {}
		if ret != _|_ {
			raises: a: 1
		}
	}

	// Same as above test, but different order. It may be that the specific
	// fields that are added are different for the two cases. This is fine as
	// long as the parent fails, as that error is ultimately what represents
	// the value as a whole.
	cycleFail: t2: p2: {
		ret: {}
		if ret != _|_ {
			raises: a: 1
		}
		raises: {}
		if raises == _|_ {
			ret: a: 1
		}
	}

	// This test should fail similarly to the above tests. The fields ret and
	// raises are not concrete, but may still become a struct and thus need
	// to be recursively checked.
	cycleFail: t3: p1: {
		raises: _
		if raises == _|_ {
			ret: a: 1
		}
		ret: _
		if ret != _|_ {
			raises: a: 1
		}
	}

	cycleFail: t3: p2: {
		ret: _
		if ret != _|_ {
			raises: a: 1
		}
		raises: _
		if raises == _|_ {
			ret: a: 1
		}
	}

	defCloseSuccess: {
		#Example: {
			raises?: {
				runtime?: string
			}

			if raises == _|_ {
				ret?: _
			}
		}

		expr: #Example & {
			ret: 2
		}
	}
}

-- nestedchain.cue --
// Issue
nestedChain: {
	cycleFail: {
		if #E.x != _|_ {
			#E: y: true
		}
		if #E.y == _|_ {
			#E: x: true
		}
		#E: [_]: bool
	}

	brokenCycleSuccess: {
		if #E.x != _|_ {
			#E: y: true
		}
		if #E.y == _|_ {
			#E: x: true
		}
		#E: [_]: bool
		#E: x:   true
	}

	doubleAddfail: {
		if #E.x == _|_ {
			#E: y: true
		}
		if #E.y == _|_ {
			#E: x: true
		}
		#E: [_]: bool
	}

	trippleSuccess: {
		if #E.x != _|_ {
			#E: y: true
		}
		if #E.y != _|_ {
			z: true
		}
		#E: x: true
	}
}
-- issue3836.cue --
issue3836: hidden: {
	_Value: {
		foo?: _
		bar?: _
		if (foo | bar) == _|_ {
			bar: type: "bar"
		}
		out: [if bar != _|_ {"bar is set"}]
	}
	_Value.out
}
issue3836: exposed: {
	foo?: _
	bar?: _
	if (foo | bar) == _|_ {
		bar: type: "bar"
	}
	out: [if bar != _|_ {"bar is set"}]
}
-- issue3838.cue --
issue3838: {
	#T: {
		subject: {
			in: opt?: foo: int
			out: [
				if in.opt != _|_ {in.opt.foo},
				0,
			][0]
		}
		_test: {
			assert: {
				pass: bool
			}
			assert: {
				notOk: _
				pass:  false
			} | {
				invoke: _
				res:    subject.out
				pass:   true
			}
		}
		results: _test.assert.pass
	}
	(#T & {
		_test: assert: invoke: "foo"
	}).results
}
-- out/eval/stats --
Leaks:  29
Freed:  207
Reused: 201
Allocs: 35
Retain: 104

Unifications: 220
Conjuncts:    279
Disjuncts:    302
-- out/evalalpha --
(struct){
  self: (struct){
    fail: (struct){
      a: (_|_){
        // [incomplete] self.fail.a.b: cyclic reference to field b:
        //     ./in.cue:6:4
      }
    }
    isConcreteFail: (struct){
      t1: (struct){
        a: (struct){
          b: (int){ 1 }
        }
      }
      t2: (struct){
        a: (_|_){
          // [cycle] self.isConcreteFail.t2.a: circular dependency in evaluation of conditionals: a.b changed after evaluation:
          //     ./in.cue:25:7
        }
      }
    }
    isNotConcrete: (struct){
      t1: (struct){
        a: (struct){
          b: (int){ int }
        }
      }
      t2: (struct){
        a: (struct){
          b?: (int){ int }
        }
      }
    }
  }
  issue3836: (struct){
    hidden: (#list){
      _Value: (_|_){
        // [incomplete] issue3836.hidden._Value.bar.type: cyclic reference to field type:
        //     ./issue3836.cue:5:3
        foo?: (_){ _ }
        bar?: (struct){
        }
        out: (#list){
        }
      }
    }
    exposed: (_|_){
      // [cycle] issue3836.exposed: circular dependency in evaluation of conditionals: (foo|bar) changed after evaluation:
      //     ./issue3836.cue:15:6
    }
  }
  issue3838: (bool){
    true
    #T: (#struct){
      subject: (#struct){
        in: (#struct){
          opt?: (#struct){
            foo: (int){ int }
          }
        }
        out: (int){ 0 }
      }
      _test: (#struct){
        assert: (#struct){ |((#struct){
            pass: (bool){ false }
            notOk: (_){ _ }
          }, (#struct){
            pass: (bool){ true }
            invoke: (_){ _ }
            res: (int){ 0 }
          }) }
      }
      results: (_|_){
        // [incomplete] issue3838.#T.results: unresolved disjunction {pass:false,notOk:_} | {pass:true,invoke:_,res:0} (type struct):
        //     ./issue3838.cue:23:12
      }
    }
  }
  mutual: (struct){
    noConflicts: (struct){
      a: (struct){
        new: (string){ "" }
      }
      b: (struct){
        new: (string){ "" }
      }
    }
    mutualCycleFail: (struct){
      b: (_|_){
        // [incomplete] mutual.mutualCycleFail.b.foo: cyclic reference to field foo:
        //     ./mutual.cue:8:7
      }
      a: (_|_){
        // [incomplete] mutual.mutualCycleFail.a.bar: cyclic reference to field bar:
        //     ./mutual.cue:9:7
      }
    }
    brokenCycleSuccess: (struct){
      a: (struct){
        foo: (string){ "" }
        bar: (string){ "" }
      }
      b: (struct){
      }
    }
    allowOneDirectionalDependency: (struct){
      p1: (struct){
        a: (struct){
          bar: (string){ "" }
        }
        b: (struct){
        }
      }
      p2: (struct){
        a: (struct){
        }
        b: (struct){
          foo: (string){ "" }
        }
      }
    }
    oneDirectionalBrokenConflictSuccess: (struct){
      p1: (struct){
        b: (struct){
          foo: (string){ "" }
          new: (string){ "" }
        }
        a: (struct){
        }
      }
      p2: (struct){
        a: (struct){
        }
        b: (struct){
          foo: (string){ "" }
          new: (string){ "" }
        }
      }
      p3: (struct){
        a: (struct){
        }
        b: (struct){
          new: (string){ "" }
          foo: (string){ "" }
        }
      }
      p4: (struct){
        b: (struct){
          foo: (string){ "" }
          new: (string){ "" }
        }
        a: (struct){
        }
      }
      p5: (struct){
        b: (struct){
          new: (string){ "" }
          foo: (string){ "" }
        }
        a: (struct){
        }
      }
      p6: (struct){
        b: (struct){
          new: (string){ "" }
          foo: (string){ "" }
        }
        a: (struct){
        }
      }
    }
  }
  sameStruct: (struct){
    chainSuccess: (struct){
      a: (struct){
        raises?: (struct){
        }
        ret: (struct){
          a: (int){ 1 }
        }
        foo: (struct){
          a: (int){ 1 }
        }
      }
      b: (struct){
        foo: (struct){
          a: (int){ 1 }
        }
        raises?: (struct){
        }
        ret: (struct){
          a: (int){ 1 }
        }
      }
    }
    cycleFail: (struct){
      t1: (struct){
        p1: (_|_){
          // [cycle] sameStruct.cycleFail.t1.p1: circular dependency in evaluation of conditionals: raises changed after evaluation:
          //     ./mutualsamestruct.cue:26:6
        }
        p2: (_|_){
          // [cycle] sameStruct.cycleFail.t1.p2: circular dependency in evaluation of conditionals: ret changed after evaluation:
          //     ./mutualsamestruct.cue:37:6
        }
      }
      t2: (struct){
        p1: (_|_){
          // [cycle] sameStruct.cycleFail.t2.p1: circular dependency in evaluation of conditionals: raises changed after evaluation:
          //     ./mutualsamestruct.cue:54:6
        }
        p2: (_|_){
          // [cycle] sameStruct.cycleFail.t2.p2: circular dependency in evaluation of conditionals: ret changed after evaluation:
          //     ./mutualsamestruct.cue:69:6
        }
      }
      t3: (struct){
        p1: (_|_){
          // [cycle] sameStruct.cycleFail.t3.p1: circular dependency in evaluation of conditionals: raises changed after evaluation:
          //     ./mutualsamestruct.cue:83:6
        }
        p2: (_|_){
          // [cycle] sameStruct.cycleFail.t3.p2: circular dependency in evaluation of conditionals: ret changed after evaluation:
          //     ./mutualsamestruct.cue:94:6
        }
      }
    }
    defCloseSuccess: (struct){
      #Example: (#struct){
        raises?: (#struct){
          runtime?: (string){ string }
        }
        ret?: (_){ _ }
      }
      expr: (#struct){
        ret: (int){ 2 }
        raises?: (#struct){
          runtime?: (string){ string }
        }
      }
    }
  }
  nestedChain: (struct){
    cycleFail: (_|_){
      // [incomplete] nestedChain.cycleFail.#E.x: cyclic reference to field x:
      //     ./nestedchain.cue:7:3
      #E: (#struct){
      }
    }
    brokenCycleSuccess: (struct){
      #E: (#struct){
        y: (bool){ true }
        x: (bool){ true }
      }
    }
    doubleAddfail: (_|_){
      // [incomplete] nestedChain.doubleAddfail.#E.y: cyclic reference to field y:
      //     ./nestedchain.cue:25:3
      // nestedChain.doubleAddfail.#E.x: cyclic reference to field x:
      //     ./nestedchain.cue:28:3
      #E: (#struct){
      }
    }
    trippleSuccess: (struct){
      #E: (#struct){
        y: (bool){ true }
        x: (bool){ true }
      }
      z: (bool){ true }
    }
  }
}
-- diff/-out/evalalpha<==>+out/eval --
diff old new
--- old
+++ new
@@ -2,14 +2,14 @@
   self: (struct){
     fail: (struct){
       a: (_|_){
-        // [cycle] self.fail.a: cycle with field a.b:
-        //     ./in.cue:6:7
+        // [incomplete] self.fail.a.b: cyclic reference to field b:
+        //     ./in.cue:6:4
       }
     }
     isConcreteFail: (struct){
       t1: (struct){
-        a: (_|_){
-          // [cycle] cycle error
+        a: (struct){
+          b: (int){ 1 }
         }
       }
       t2: (struct){
@@ -21,8 +21,8 @@
     }
     isNotConcrete: (struct){
       t1: (struct){
-        a: (_|_){
-          // [cycle] cycle error
+        a: (struct){
+          b: (int){ int }
         }
       }
       t2: (struct){
@@ -35,10 +35,14 @@
   issue3836: (struct){
     hidden: (#list){
       _Value: (_|_){
-        // [cycle] issue3836.hidden._Value: circular dependency in evaluation of conditionals: (foo|bar) changed after evaluation:
-        //     ./issue3836.cue:5:7
-      }
-      0: (string){ "bar is set" }
+        // [incomplete] issue3836.hidden._Value.bar.type: cyclic reference to field type:
+        //     ./issue3836.cue:5:3
+        foo?: (_){ _ }
+        bar?: (struct){
+        }
+        out: (#list){
+        }
+      }
     }
     exposed: (_|_){
       // [cycle] issue3836.exposed: circular dependency in evaluation of conditionals: (foo|bar) changed after evaluation:
@@ -83,12 +87,12 @@
     }
     mutualCycleFail: (struct){
       b: (_|_){
-        // [cycle] mutual.mutualCycleFail.a: cycle with field b.foo:
-        //     ./mutual.cue:9:10
-      }
-      a: (_|_){
-        // [cycle] mutual.mutualCycleFail.a: cycle with field b.foo:
-        //     ./mutual.cue:9:10
+        // [incomplete] mutual.mutualCycleFail.b.foo: cyclic reference to field foo:
+        //     ./mutual.cue:8:7
+      }
+      a: (_|_){
+        // [incomplete] mutual.mutualCycleFail.a.bar: cyclic reference to field bar:
+        //     ./mutual.cue:9:7
       }
     }
     brokenCycleSuccess: (struct){
@@ -229,17 +233,19 @@
         ret?: (_){ _ }
       }
       expr: (#struct){
-        raises?: (#struct){
-          runtime?: (string){ string }
-        }
         ret: (int){ 2 }
+        raises?: (#struct){
+          runtime?: (string){ string }
+        }
       }
     }
   }
   nestedChain: (struct){
     cycleFail: (_|_){
-      // [cycle] nestedChain.cycleFail: cycle with field #E.y:
-      //     ./nestedchain.cue:7:6
+      // [incomplete] nestedChain.cycleFail.#E.x: cyclic reference to field x:
+      //     ./nestedchain.cue:7:3
+      #E: (#struct){
+      }
     }
     brokenCycleSuccess: (struct){
       #E: (#struct){
@@ -248,8 +254,12 @@
       }
     }
     doubleAddfail: (_|_){
-      // [cycle] nestedChain.doubleAddfail: cycle with field #E.y:
-      //     ./nestedchain.cue:28:6
+      // [incomplete] nestedChain.doubleAddfail.#E.y: cyclic reference to field y:
+      //     ./nestedchain.cue:25:3
+      // nestedChain.doubleAddfail.#E.x: cyclic reference to field x:
+      //     ./nestedchain.cue:28:3
+      #E: (#struct){
+      }
     }
     trippleSuccess: (struct){
       #E: (#struct){
-- diff/explanation --
self.isConcreteFail: t1: int value is not an error.
self.isNotConcrete: t1: int value is not an error.
-- out/eval --
(struct){
  self: (struct){
    fail: (struct){
      a: (_|_){
        // [cycle] self.fail.a: cycle with field a.b:
        //     ./in.cue:6:7
      }
    }
    isConcreteFail: (struct){
      t1: (struct){
        a: (_|_){
          // [cycle] cycle error
        }
      }
      t2: (struct){
        a: (_|_){
          // [cycle] self.isConcreteFail.t2.a: circular dependency in evaluation of conditionals: a.b changed after evaluation:
          //     ./in.cue:25:7
        }
      }
    }
    isNotConcrete: (struct){
      t1: (struct){
        a: (_|_){
          // [cycle] cycle error
        }
      }
      t2: (struct){
        a: (struct){
          b?: (int){ int }
        }
      }
    }
  }
  issue3836: (struct){
    hidden: (#list){
      _Value: (_|_){
        // [cycle] issue3836.hidden._Value: circular dependency in evaluation of conditionals: (foo|bar) changed after evaluation:
        //     ./issue3836.cue:5:7
      }
      0: (string){ "bar is set" }
    }
    exposed: (_|_){
      // [cycle] issue3836.exposed: circular dependency in evaluation of conditionals: (foo|bar) changed after evaluation:
      //     ./issue3836.cue:15:6
    }
  }
  issue3838: (bool){
    true
    #T: (#struct){
      subject: (#struct){
        in: (#struct){
          opt?: (#struct){
            foo: (int){ int }
          }
        }
        out: (int){ 0 }
      }
      _test: (#struct){
        assert: (#struct){ |((#struct){
            pass: (bool){ false }
            notOk: (_){ _ }
          }, (#struct){
            pass: (bool){ true }
            invoke: (_){ _ }
            res: (int){ 0 }
          }) }
      }
      results: (_|_){
        // [incomplete] issue3838.#T.results: unresolved disjunction {pass:false,notOk:_} | {pass:true,invoke:_,res:0} (type struct):
        //     ./issue3838.cue:23:12
      }
    }
  }
  mutual: (struct){
    noConflicts: (struct){
      a: (struct){
        new: (string){ "" }
      }
      b: (struct){
        new: (string){ "" }
      }
    }
    mutualCycleFail: (struct){
      b: (_|_){
        // [cycle] mutual.mutualCycleFail.a: cycle with field b.foo:
        //     ./mutual.cue:9:10
      }
      a: (_|_){
        // [cycle] mutual.mutualCycleFail.a: cycle with field b.foo:
        //     ./mutual.cue:9:10
      }
    }
    brokenCycleSuccess: (struct){
      a: (struct){
        foo: (string){ "" }
        bar: (string){ "" }
      }
      b: (struct){
      }
    }
    allowOneDirectionalDependency: (struct){
      p1: (struct){
        a: (struct){
          bar: (string){ "" }
        }
        b: (struct){
        }
      }
      p2: (struct){
        a: (struct){
        }
        b: (struct){
          foo: (string){ "" }
        }
      }
    }
    oneDirectionalBrokenConflictSuccess: (struct){
      p1: (struct){
        b: (struct){
          foo: (string){ "" }
          new: (string){ "" }
        }
        a: (struct){
        }
      }
      p2: (struct){
        a: (struct){
        }
        b: (struct){
          foo: (string){ "" }
          new: (string){ "" }
        }
      }
      p3: (struct){
        a: (struct){
        }
        b: (struct){
          new: (string){ "" }
          foo: (string){ "" }
        }
      }
      p4: (struct){
        b: (struct){
          foo: (string){ "" }
          new: (string){ "" }
        }
        a: (struct){
        }
      }
      p5: (struct){
        b: (struct){
          new: (string){ "" }
          foo: (string){ "" }
        }
        a: (struct){
        }
      }
      p6: (struct){
        b: (struct){
          new: (string){ "" }
          foo: (string){ "" }
        }
        a: (struct){
        }
      }
    }
  }
  sameStruct: (struct){
    chainSuccess: (struct){
      a: (struct){
        raises?: (struct){
        }
        ret: (struct){
          a: (int){ 1 }
        }
        foo: (struct){
          a: (int){ 1 }
        }
      }
      b: (struct){
        foo: (struct){
          a: (int){ 1 }
        }
        raises?: (struct){
        }
        ret: (struct){
          a: (int){ 1 }
        }
      }
    }
    cycleFail: (struct){
      t1: (struct){
        p1: (_|_){
          // [cycle] sameStruct.cycleFail.t1.p1: circular dependency in evaluation of conditionals: raises changed after evaluation:
          //     ./mutualsamestruct.cue:26:6
        }
        p2: (_|_){
          // [cycle] sameStruct.cycleFail.t1.p2: circular dependency in evaluation of conditionals: ret changed after evaluation:
          //     ./mutualsamestruct.cue:37:6
        }
      }
      t2: (struct){
        p1: (_|_){
          // [cycle] sameStruct.cycleFail.t2.p1: circular dependency in evaluation of conditionals: raises changed after evaluation:
          //     ./mutualsamestruct.cue:54:6
        }
        p2: (_|_){
          // [cycle] sameStruct.cycleFail.t2.p2: circular dependency in evaluation of conditionals: ret changed after evaluation:
          //     ./mutualsamestruct.cue:69:6
        }
      }
      t3: (struct){
        p1: (_|_){
          // [cycle] sameStruct.cycleFail.t3.p1: circular dependency in evaluation of conditionals: raises changed after evaluation:
          //     ./mutualsamestruct.cue:83:6
        }
        p2: (_|_){
          // [cycle] sameStruct.cycleFail.t3.p2: circular dependency in evaluation of conditionals: ret changed after evaluation:
          //     ./mutualsamestruct.cue:94:6
        }
      }
    }
    defCloseSuccess: (struct){
      #Example: (#struct){
        raises?: (#struct){
          runtime?: (string){ string }
        }
        ret?: (_){ _ }
      }
      expr: (#struct){
        raises?: (#struct){
          runtime?: (string){ string }
        }
        ret: (int){ 2 }
      }
    }
  }
  nestedChain: (struct){
    cycleFail: (_|_){
      // [cycle] nestedChain.cycleFail: cycle with field #E.y:
      //     ./nestedchain.cue:7:6
    }
    brokenCycleSuccess: (struct){
      #E: (#struct){
        y: (bool){ true }
        x: (bool){ true }
      }
    }
    doubleAddfail: (_|_){
      // [cycle] nestedChain.doubleAddfail: cycle with field #E.y:
      //     ./nestedchain.cue:28:6
    }
    trippleSuccess: (struct){
      #E: (#struct){
        y: (bool){ true }
        x: (bool){ true }
      }
      z: (bool){ true }
    }
  }
}
-- out/compile --
--- in.cue
{
  self: {
    fail: {
      a: {
        if (〈1;a〉.b == _|_(explicit error (_|_ literal) in source)) {
          b: 1
        }
      }
    }
    isConcreteFail: {
      t1: {
        a: {
          if (〈1;a〉.b == _|_(explicit error (_|_ literal) in source)) {
            b: 1
          }
          b: int
        }
      }
    }
    isConcreteFail: {
      t2: {
        a: {
          if (〈1;a〉.b == _|_(explicit error (_|_ literal) in source)) {
            b: 1
          }
          b?: int
        }
      }
    }
    isNotConcrete: {
      t1: {
        a: {
          if (〈1;a〉.b != _|_(explicit error (_|_ literal) in source)) {
            b: 1
          }
          b: int
        }
      }
    }
    isNotConcrete: {
      t2: {
        a: {
          if (〈1;a〉.b != _|_(explicit error (_|_ literal) in source)) {
            b: 1
          }
          b?: int
        }
      }
    }
  }
}
--- issue3836.cue
{
  issue3836: {
    hidden: {
      _Value: {
        foo?: _
        bar?: _
        if ((〈0;foo〉|〈0;bar〉) == _|_(explicit error (_|_ literal) in source)) {
          bar: {
            type: "bar"
          }
        }
        out: [
          if (〈1;bar〉 != _|_(explicit error (_|_ literal) in source)) {
            "bar is set"
          },
        ]
      }
      〈0;_Value〉.out
    }
  }
  issue3836: {
    exposed: {
      foo?: _
      bar?: _
      if ((〈0;foo〉|〈0;bar〉) == _|_(explicit error (_|_ literal) in source)) {
        bar: {
          type: "bar"
        }
      }
      out: [
        if (〈1;bar〉 != _|_(explicit error (_|_ literal) in source)) {
          "bar is set"
        },
      ]
    }
  }
}
--- issue3838.cue
{
  issue3838: {
    #T: {
      subject: {
        in: {
          opt?: {
            foo: int
          }
        }
        out: [
          if (〈1;in〉.opt != _|_(explicit error (_|_ literal) in source)) {
            〈2;in〉.opt.foo
          },
          0,
        ][0]
      }
      _test: {
        assert: {
          pass: bool
        }
        assert: ({
          notOk: _
          pass: false
        }|{
          invoke: _
          res: 〈2;subject〉.out
          pass: true
        })
      }
      results: 〈0;_test〉.assert.pass
    }
    (〈0;#T〉 & {
      _test: {
        assert: {
          invoke: "foo"
        }
      }
    }).results
  }
}
--- mutual.cue
{
  mutual: {
    noConflicts: {
      a: {
        if (〈1;b〉.foo == _|_(explicit error (_|_ literal) in source)) {
          new: ""
        }
      }
      b: {
        if (〈1;a〉.bar == _|_(explicit error (_|_ literal) in source)) {
          new: ""
        }
      }
    }
    mutualCycleFail: {
      b: {
        if (〈1;a〉.bar == _|_(explicit error (_|_ literal) in source)) {
          foo: ""
        }
      }
      a: {
        if (〈1;b〉.foo == _|_(explicit error (_|_ literal) in source)) {
          bar: ""
        }
      }
    }
    brokenCycleSuccess: {
      a: {
        if (〈1;b〉.foo == _|_(explicit error (_|_ literal) in source)) {
          foo: ""
        }
      }
      b: {
        if (〈1;a〉.bar == _|_(explicit error (_|_ literal) in source)) {
          bar: ""
        }
      }
      a: {
        bar: ""
      }
    }
    allowOneDirectionalDependency: {
      p1: {
        a: {
          if (〈1;b〉.foo == _|_(explicit error (_|_ literal) in source)) {
            bar: ""
          }
        }
        b: {
          if (〈1;a〉.bar == _|_(explicit error (_|_ literal) in source)) {
            new: ""
          }
        }
      }
      p2: {
        a: {
          if (〈1;b〉.foo == _|_(explicit error (_|_ literal) in source)) {
            new: ""
          }
        }
        b: {
          if (〈1;a〉.bar == _|_(explicit error (_|_ literal) in source)) {
            foo: ""
          }
        }
      }
    }
    oneDirectionalBrokenConflictSuccess: {
      p1: {
        b: {
          foo: ""
        }
        a: {
          if (〈1;b〉.foo == _|_(explicit error (_|_ literal) in source)) {
            bar: ""
          }
        }
        b: {
          if (〈1;a〉.bar == _|_(explicit error (_|_ literal) in source)) {
            new: ""
          }
        }
      }
    }
    oneDirectionalBrokenConflictSuccess: {
      p2: {
        a: {
          if (〈1;b〉.foo == _|_(explicit error (_|_ literal) in source)) {
            bar: ""
          }
        }
        b: {
          foo: ""
        }
        b: {
          if (〈1;a〉.bar == _|_(explicit error (_|_ literal) in source)) {
            new: ""
          }
        }
      }
    }
    oneDirectionalBrokenConflictSuccess: {
      p3: {
        a: {
          if (〈1;b〉.foo == _|_(explicit error (_|_ literal) in source)) {
            bar: ""
          }
        }
        b: {
          if (〈1;a〉.bar == _|_(explicit error (_|_ literal) in source)) {
            new: ""
          }
        }
        b: {
          foo: ""
        }
      }
    }
    oneDirectionalBrokenConflictSuccess: {
      p4: {
        b: {
          foo: ""
        }
        b: {
          if (〈1;a〉.bar == _|_(explicit error (_|_ literal) in source)) {
            new: ""
          }
        }
        a: {
          if (〈1;b〉.foo == _|_(explicit error (_|_ literal) in source)) {
            bar: ""
          }
        }
      }
    }
    oneDirectionalBrokenConflictSuccess: {
      p5: {
        b: {
          if (〈1;a〉.bar == _|_(explicit error (_|_ literal) in source)) {
            new: ""
          }
        }
        b: {
          foo: ""
        }
        a: {
          if (〈1;b〉.foo == _|_(explicit error (_|_ literal) in source)) {
            bar: ""
          }
        }
      }
    }
    oneDirectionalBrokenConflictSuccess: {
      p6: {
        b: {
          if (〈1;a〉.bar == _|_(explicit error (_|_ literal) in source)) {
            new: ""
          }
        }
        a: {
          if (〈1;b〉.foo == _|_(explicit error (_|_ literal) in source)) {
            bar: ""
          }
        }
        b: {
          foo: ""
        }
      }
    }
  }
}
--- mutualsamestruct.cue
{
  sameStruct: {
    chainSuccess: {
      a: {
        raises?: {}
        if (〈0;raises〉 == _|_(explicit error (_|_ literal) in source)) {
          ret: {
            a: 1
          }
        }
        ret?: {}
        if (〈0;ret〉 != _|_(explicit error (_|_ literal) in source)) {
          foo: {
            a: 1
          }
        }
      }
    }
    chainSuccess: {
      b: {
        if (〈0;ret〉 != _|_(explicit error (_|_ literal) in source)) {
          foo: {
            a: 1
          }
        }
        raises?: {}
        if (〈0;raises〉 == _|_(explicit error (_|_ literal) in source)) {
          ret: {
            a: 1
          }
        }
        ret?: {}
      }
    }
    cycleFail: {
      t1: {
        p1: {
          raises?: {}
          if (〈0;raises〉 == _|_(explicit error (_|_ literal) in source)) {
            ret: {
              a: 1
            }
          }
          ret?: {}
          if (〈0;ret〉 != _|_(explicit error (_|_ literal) in source)) {
            raises: {
              a: 1
            }
          }
        }
      }
    }
    cycleFail: {
      t1: {
        p2: {
          ret?: {}
          if (〈0;ret〉 != _|_(explicit error (_|_ literal) in source)) {
            raises: {
              a: 1
            }
          }
          raises?: {}
          if (〈0;raises〉 == _|_(explicit error (_|_ literal) in source)) {
            ret: {
              a: 1
            }
          }
        }
      }
    }
    cycleFail: {
      t2: {
        p1: {
          raises: {}
          if (〈0;raises〉 == _|_(explicit error (_|_ literal) in source)) {
            ret: {
              a: 1
            }
          }
          ret: {}
          if (〈0;ret〉 != _|_(explicit error (_|_ literal) in source)) {
            raises: {
              a: 1
            }
          }
        }
      }
    }
    cycleFail: {
      t2: {
        p2: {
          ret: {}
          if (〈0;ret〉 != _|_(explicit error (_|_ literal) in source)) {
            raises: {
              a: 1
            }
          }
          raises: {}
          if (〈0;raises〉 == _|_(explicit error (_|_ literal) in source)) {
            ret: {
              a: 1
            }
          }
        }
      }
    }
    cycleFail: {
      t3: {
        p1: {
          raises: _
          if (〈0;raises〉 == _|_(explicit error (_|_ literal) in source)) {
            ret: {
              a: 1
            }
          }
          ret: _
          if (〈0;ret〉 != _|_(explicit error (_|_ literal) in source)) {
            raises: {
              a: 1
            }
          }
        }
      }
    }
    cycleFail: {
      t3: {
        p2: {
          ret: _
          if (〈0;ret〉 != _|_(explicit error (_|_ literal) in source)) {
            raises: {
              a: 1
            }
          }
          raises: _
          if (〈0;raises〉 == _|_(explicit error (_|_ literal) in source)) {
            ret: {
              a: 1
            }
          }
        }
      }
    }
    defCloseSuccess: {
      #Example: {
        raises?: {
          runtime?: string
        }
        if (〈0;raises〉 == _|_(explicit error (_|_ literal) in source)) {
          ret?: _
        }
      }
      expr: (〈0;#Example〉 & {
        ret: 2
      })
    }
  }
}
--- nestedchain.cue
{
  nestedChain: {
    cycleFail: {
      if (〈0;#E〉.x != _|_(explicit error (_|_ literal) in source)) {
        #E: {
          y: true
        }
      }
      if (〈0;#E〉.y == _|_(explicit error (_|_ literal) in source)) {
        #E: {
          x: true
        }
      }
      #E: {
        [_]: bool
      }
    }
    brokenCycleSuccess: {
      if (〈0;#E〉.x != _|_(explicit error (_|_ literal) in source)) {
        #E: {
          y: true
        }
      }
      if (〈0;#E〉.y == _|_(explicit error (_|_ literal) in source)) {
        #E: {
          x: true
        }
      }
      #E: {
        [_]: bool
      }
      #E: {
        x: true
      }
    }
    doubleAddfail: {
      if (〈0;#E〉.x == _|_(explicit error (_|_ literal) in source)) {
        #E: {
          y: true
        }
      }
      if (〈0;#E〉.y == _|_(explicit error (_|_ literal) in source)) {
        #E: {
          x: true
        }
      }
      #E: {
        [_]: bool
      }
    }
    trippleSuccess: {
      if (〈0;#E〉.x != _|_(explicit error (_|_ literal) in source)) {
        #E: {
          y: true
        }
      }
      if (〈0;#E〉.y != _|_(explicit error (_|_ literal) in source)) {
        z: true
      }
      #E: {
        x: true
      }
    }
  }
}
