#name: definitions with embedding
#evalPartial
-- in.cue --
#E: {
	a: {b: int}
}

#S: {
	#E
	a: {c: int}
	b: 3
}

// adding a field to a nested struct that is closed.
#e1: #S & {a: d: 4}

// literal struct not closed until after unification.
#v1: #S & {a: c: 4}
-- out/def --
#E: {
	a: {
		b: int
	}
}
#S: {
	a: {
		c: int
	}
	b: 3
	#E
}

// adding a field to a nested struct that is closed.
#e1: #S & {
	a: {
		d: 4
	}
}

// literal struct not closed until after unification.
#v1: #S & {
	a: {
		c: 4
	}
}
-- out/export --

-- out/yaml --
{}
-- out/json --
{}
-- out/legacy-debug --
<0>{#E: <1>C{a: <2>C{b: int}}, #S: <3>C{a: <4>C{b: int, c: int}, b: 3}, #e1: <5>C{a: _|_(4:field "d" not allowed in closed struct), b: 3}, #v1: <6>C{a: <7>C{b: int, c: 4}, b: 3}}
-- out/compile --
--- in.cue
{
  #E: {
    a: {
      b: int
    }
  }
  #S: {
    〈1;#E〉
    a: {
      c: int
    }
    b: 3
  }
  #e1: (〈0;#S〉 & {
    a: {
      d: 4
    }
  })
  #v1: (〈0;#S〉 & {
    a: {
      c: 4
    }
  })
}
-- out/eval/stats --
Leaks:  0
Freed:  20
Reused: 16
Allocs: 4
Retain: 0

Unifications: 20
Conjuncts:    36
Disjuncts:    20
-- out/evalalpha --
Errors:
#e1.a.d: field not allowed:
    ./in.cue:12:15

Result:
(_|_){
  // [eval]
  #E: (#struct){
    a: (#struct){
      b: (int){ int }
    }
  }
  #S: (#struct){
    a: (#struct){
      c: (int){ int }
      b: (int){ int }
    }
    b: (int){ 3 }
  }
  #e1: (_|_){
    // [eval]
    a: (_|_){
      // [eval]
      d: (_|_){
        // [eval] #e1.a.d: field not allowed:
        //     ./in.cue:12:15
      }
      c: (int){ int }
      b: (int){ int }
    }
    b: (int){ 3 }
  }
  #v1: (#struct){
    a: (#struct){
      c: (int){ 4 }
      b: (int){ int }
    }
    b: (int){ 3 }
  }
}
-- diff/-out/evalalpha<==>+out/eval --
diff old new
--- old
+++ new
@@ -1,9 +1,5 @@
 Errors:
 #e1.a.d: field not allowed:
-    ./in.cue:2:5
-    ./in.cue:6:2
-    ./in.cue:7:5
-    ./in.cue:12:6
     ./in.cue:12:15
 
 Result:
@@ -16,8 +12,8 @@
   }
   #S: (#struct){
     a: (#struct){
-      b: (int){ int }
-      c: (int){ int }
+      c: (int){ int }
+      b: (int){ int }
     }
     b: (int){ 3 }
   }
@@ -25,23 +21,19 @@
     // [eval]
     a: (_|_){
       // [eval]
-      b: (int){ int }
-      c: (int){ int }
       d: (_|_){
         // [eval] #e1.a.d: field not allowed:
-        //     ./in.cue:2:5
-        //     ./in.cue:6:2
-        //     ./in.cue:7:5
-        //     ./in.cue:12:6
         //     ./in.cue:12:15
       }
+      c: (int){ int }
+      b: (int){ int }
     }
     b: (int){ 3 }
   }
   #v1: (#struct){
     a: (#struct){
-      b: (int){ int }
       c: (int){ 4 }
+      b: (int){ int }
     }
     b: (int){ 3 }
   }
-- diff/todo/p2 --
Reordering / missing positions.
-- out/eval --
Errors:
#e1.a.d: field not allowed:
    ./in.cue:2:5
    ./in.cue:6:2
    ./in.cue:7:5
    ./in.cue:12:6
    ./in.cue:12:15

Result:
(_|_){
  // [eval]
  #E: (#struct){
    a: (#struct){
      b: (int){ int }
    }
  }
  #S: (#struct){
    a: (#struct){
      b: (int){ int }
      c: (int){ int }
    }
    b: (int){ 3 }
  }
  #e1: (_|_){
    // [eval]
    a: (_|_){
      // [eval]
      b: (int){ int }
      c: (int){ int }
      d: (_|_){
        // [eval] #e1.a.d: field not allowed:
        //     ./in.cue:2:5
        //     ./in.cue:6:2
        //     ./in.cue:7:5
        //     ./in.cue:12:6
        //     ./in.cue:12:15
      }
    }
    b: (int){ 3 }
  }
  #v1: (#struct){
    a: (#struct){
      b: (int){ int }
      c: (int){ 4 }
    }
    b: (int){ 3 }
  }
}
