-- in.cue --
reduced: t1: {
	S: { if true { a: U } }
	x: S
	x: {
	["a"]: b: 1 | T
	d: b: x.a
	}
	T: 1
	U: b: 1 | 1
}
issue3851: t1: {
	#Top: _
	#Config: {
	disj: _ | *"default"
	shared: _
	}

	#Schema: {
	[string]: #Config
	if true {
		one: shared: "foo"
	}
	}

	out: #Schema
	out: {
	["one"]: disj: _ | #Top
	two: shared: out.one.shared
	}
}
issue3851: t2: {
	#Top: _
	#Config: {
	disj: _ | *{}
	shared: _
	}

	#Env: {
	conf: [string]: #Config
	if true {
		conf: one: shared: "foo"
	}
	}

	env1: #Env

	[string]: {
	conf: ["one"]: disj: {} | #Top
	conf: two: shared: conf.one.shared
	}
}
-- out/eval/stats --
Leaks:  6
Freed:  90
Reused: 79
Allocs: 17
Retain: 2

Unifications: 60
Conjuncts:    151
Disjuncts:    98
-- out/evalalpha --
(struct){
  reduced: (struct){
    t1: (struct){
      S: (struct){
        a: ~(reduced.t1.U)
      }
      x: (struct){
        d: (struct){
          b: ~(reduced.t1.x.a)
        }
        a: (struct){
          b: (int){ 1 }
        }
      }
      T: (int){ 1 }
      U: (struct){
        b: (int){ 1 }
      }
    }
  }
  issue3851: (struct){
    t1: (struct){
      #Top: (_){ _ }
      #Config: (#struct){
        disj: (_){ |(*(string){ "default" }, (_){ _ }) }
        shared: (_){ _ }
      }
      #Schema: (#struct){
        one: (#struct){
          shared: (string){ "foo" }
          disj: (_){ |(*(string){ "default" }, (_){ _ }) }
        }
      }
      out: (#struct){
        two: (#struct){
          shared: (string){ "foo" }
          disj: (_){ |(*(string){ "default" }, (_){ _ }) }
        }
        one: (#struct){
          shared: (string){ "foo" }
          disj: (_){ _ }
        }
      }
    }
    t2: (struct){
      #Top: (_){ _ }
      #Config: (#struct){
        disj: (_){ |(*(#struct){
          }, (_){ _ }) }
        shared: (_){ _ }
      }
      #Env: (#struct){
        conf: (#struct){
          one: (#struct){
            shared: (string){ "foo" }
            disj: (_){ |(*(#struct){
              }, (_){ _ }) }
          }
        }
      }
      env1: (#struct){
        conf: (#struct){
          two: (#struct){
            shared: (string){ "foo" }
            disj: (_){ |(*(#struct){
              }, (_){ _ }) }
          }
          one: (#struct){
            shared: (string){ "foo" }
            disj: (_){ |(*(#struct){
              }, (_){ _ }, (#struct){
              }, (_){ _ }) }
          }
        }
      }
    }
  }
}
-- diff/-out/evalalpha<==>+out/eval --
diff old new
--- old
+++ new
@@ -2,18 +2,14 @@
   reduced: (struct){
     t1: (struct){
       S: (struct){
-        a: (struct){
-          b: (int){ 1 }
-        }
+        a: ~(reduced.t1.U)
       }
       x: (struct){
-        a: (struct){
-          b: (int){ 1 }
-        }
         d: (struct){
-          b: (struct){
-            b: (int){ 1 }
-          }
+          b: ~(reduced.t1.x.a)
+        }
+        a: (struct){
+          b: (int){ 1 }
         }
       }
       T: (int){ 1 }
@@ -36,14 +32,14 @@
         }
       }
       out: (#struct){
-        one: (#struct){
-          shared: (string){ "foo" }
-          disj: (_){ |(*(string){ "default" }, (_){ _ }) }
-        }
         two: (#struct){
           shared: (string){ "foo" }
           disj: (_){ |(*(string){ "default" }, (_){ _ }) }
         }
+        one: (#struct){
+          shared: (string){ "foo" }
+          disj: (_){ _ }
+        }
       }
     }
     t2: (struct){
@@ -64,17 +60,17 @@
       }
       env1: (#struct){
         conf: (#struct){
-          one: (#struct){
-            shared: (string){ "foo" }
-            disj: (_){ |(*(#struct){
-              }, (_){ _ }, (struct){
-              }) }
-          }
           two: (#struct){
             shared: (string){ "foo" }
             disj: (_){ |(*(#struct){
               }, (_){ _ }) }
           }
+          one: (#struct){
+            shared: (string){ "foo" }
+            disj: (_){ |(*(#struct){
+              }, (_){ _ }, (#struct){
+              }, (_){ _ }) }
+          }
         }
       }
     }
-- out/eval --
(struct){
  reduced: (struct){
    t1: (struct){
      S: (struct){
        a: (struct){
          b: (int){ 1 }
        }
      }
      x: (struct){
        a: (struct){
          b: (int){ 1 }
        }
        d: (struct){
          b: (struct){
            b: (int){ 1 }
          }
        }
      }
      T: (int){ 1 }
      U: (struct){
        b: (int){ 1 }
      }
    }
  }
  issue3851: (struct){
    t1: (struct){
      #Top: (_){ _ }
      #Config: (#struct){
        disj: (_){ |(*(string){ "default" }, (_){ _ }) }
        shared: (_){ _ }
      }
      #Schema: (#struct){
        one: (#struct){
          shared: (string){ "foo" }
          disj: (_){ |(*(string){ "default" }, (_){ _ }) }
        }
      }
      out: (#struct){
        one: (#struct){
          shared: (string){ "foo" }
          disj: (_){ |(*(string){ "default" }, (_){ _ }) }
        }
        two: (#struct){
          shared: (string){ "foo" }
          disj: (_){ |(*(string){ "default" }, (_){ _ }) }
        }
      }
    }
    t2: (struct){
      #Top: (_){ _ }
      #Config: (#struct){
        disj: (_){ |(*(#struct){
          }, (_){ _ }) }
        shared: (_){ _ }
      }
      #Env: (#struct){
        conf: (#struct){
          one: (#struct){
            shared: (string){ "foo" }
            disj: (_){ |(*(#struct){
              }, (_){ _ }) }
          }
        }
      }
      env1: (#struct){
        conf: (#struct){
          one: (#struct){
            shared: (string){ "foo" }
            disj: (_){ |(*(#struct){
              }, (_){ _ }, (struct){
              }) }
          }
          two: (#struct){
            shared: (string){ "foo" }
            disj: (_){ |(*(#struct){
              }, (_){ _ }) }
          }
        }
      }
    }
  }
}
-- out/compile --
--- in.cue
{
  reduced: {
    t1: {
      S: {
        if true {
          a: 〈2;U〉
        }
      }
      x: 〈0;S〉
      x: {
        ["a"]: {
          b: (1|〈2;T〉)
        }
        d: {
          b: 〈2;x〉.a
        }
      }
      T: 1
      U: {
        b: (1|1)
      }
    }
  }
  issue3851: {
    t1: {
      #Top: _
      #Config: {
        disj: (_|*"default")
        shared: _
      }
      #Schema: {
        [string]: 〈1;#Config〉
        if true {
          one: {
            shared: "foo"
          }
        }
      }
      out: 〈0;#Schema〉
      out: {
        ["one"]: {
          disj: (_|〈2;#Top〉)
        }
        two: {
          shared: 〈2;out〉.one.shared
        }
      }
    }
  }
  issue3851: {
    t2: {
      #Top: _
      #Config: {
        disj: (_|*{})
        shared: _
      }
      #Env: {
        conf: {
          [string]: 〈2;#Config〉
        }
        if true {
          conf: {
            one: {
              shared: "foo"
            }
          }
        }
      }
      env1: 〈0;#Env〉
      [string]: {
        conf: {
          ["one"]: {
            disj: ({}|〈3;#Top〉)
          }
        }
        conf: {
          two: {
            shared: 〈2;conf〉.one.shared
          }
        }
      }
    }
  }
}
