#name: definitions
#evalPartial
-- in.cue --
#Foo: {
	field: int
	recursive: {
		field: string
	}
}

// Allowed
#Foo1: {field: int}
#Foo1: {field2: string}

foo: #Foo
foo: {feild: 2}

foo1: #Foo
foo1: {
	field: 2
	recursive: {
		feild: 2 // Not caught as per spec. TODO: change?
	}
}

#Bar: {
	field: int
	{[A=_]: int}
}
bar: #Bar
bar: {feild: 2}

#Mixed: string
Mixed:  string

mixedRec: {#Mixed: string}
mixedRec: {Mixed: string}
-- out/def --
#Foo: {
	field: int
	recursive: {
		field: string
	}
}

// Allowed
#Foo1: {
	field:  int
	field2: string
}
foo:  _|_ // field "feild" not allowed in closed struct
foo1: #Foo & {
	field: 2
	recursive: {
		feild: 2
	}
}
#Bar: {
	{[A=string]: int}
	field: int
}
bar: #Bar & {
	feild: 2
}
#Mixed: string
Mixed:  string
mixedRec: {
	#Mixed: string
	Mixed:  string
}
-- out/legacy-debug --
<0>{#Foo: <1>C{field: int, recursive: <2>C{field: string}}, #Foo1: <3>C{field: int, field2: string}, foo: _|_(2:field "feild" not allowed in closed struct), foo1: <4>C{field: 2, recursive: _|_(2:field "feild" not allowed in closed struct)}, #Bar: <5>{[]: <6>(A: string)->int, field: int}, bar: <7>{[]: <8>(A: string)->int, field: int, feild: 2}, #Mixed: string, Mixed: string, mixedRec: <9>{#Mixed: string, Mixed: string}}
-- out/compile --
--- in.cue
{
  #Foo: {
    field: int
    recursive: {
      field: string
    }
  }
  #Foo1: {
    field: int
  }
  #Foo1: {
    field2: string
  }
  foo: 〈0;#Foo〉
  foo: {
    feild: 2
  }
  foo1: 〈0;#Foo〉
  foo1: {
    field: 2
    recursive: {
      feild: 2
    }
  }
  #Bar: {
    field: int
    {
      [_]: int
    }
  }
  bar: 〈0;#Bar〉
  bar: {
    feild: 2
  }
  #Mixed: string
  Mixed: string
  mixedRec: {
    #Mixed: string
  }
  mixedRec: {
    Mixed: string
  }
}
-- out/eval/stats --
Leaks:  0
Freed:  28
Reused: 24
Allocs: 4
Retain: 0

Unifications: 28
Conjuncts:    43
Disjuncts:    28
-- out/evalalpha --
Errors:
foo.feild: field not allowed:
    ./in.cue:13:7
foo1.recursive.feild: field not allowed:
    ./in.cue:19:3

Result:
(_|_){
  // [eval]
  #Foo: (#struct){
    field: (int){ int }
    recursive: (#struct){
      field: (string){ string }
    }
  }
  #Foo1: (#struct){
    field: (int){ int }
    field2: (string){ string }
  }
  foo: (_|_){
    // [eval]
    feild: (_|_){
      // [eval] foo.feild: field not allowed:
      //     ./in.cue:13:7
    }
    field: (int){ int }
    recursive: (#struct){
      field: (string){ string }
    }
  }
  foo1: (_|_){
    // [eval]
    field: (int){ 2 }
    recursive: (_|_){
      // [eval]
      feild: (_|_){
        // [eval] foo1.recursive.feild: field not allowed:
        //     ./in.cue:19:3
      }
      field: (string){ string }
    }
  }
  #Bar: (#struct){
    field: (int){ int }
  }
  bar: (#struct){
    feild: (int){ 2 }
    field: (int){ int }
  }
  #Mixed: (string){ string }
  Mixed: (string){ string }
  mixedRec: (struct){
    #Mixed: (string){ string }
    Mixed: (string){ string }
  }
}
-- diff/-out/evalalpha<==>+out/eval --
diff old new
--- old
+++ new
@@ -1,11 +1,7 @@
 Errors:
 foo.feild: field not allowed:
-    ./in.cue:1:7
-    ./in.cue:12:6
     ./in.cue:13:7
 foo1.recursive.feild: field not allowed:
-    ./in.cue:3:13
-    ./in.cue:15:7
     ./in.cue:19:3
 
 Result:
@@ -23,16 +19,14 @@
   }
   foo: (_|_){
     // [eval]
-    field: (int){ int }
-    recursive: (#struct){
-      field: (string){ string }
-    }
     feild: (_|_){
       // [eval] foo.feild: field not allowed:
-      //     ./in.cue:1:7
-      //     ./in.cue:12:6
       //     ./in.cue:13:7
     }
+    field: (int){ int }
+    recursive: (#struct){
+      field: (string){ string }
+    }
   }
   foo1: (_|_){
     // [eval]
@@ -39,13 +33,11 @@
     field: (int){ 2 }
     recursive: (_|_){
       // [eval]
-      field: (string){ string }
       feild: (_|_){
         // [eval] foo1.recursive.feild: field not allowed:
-        //     ./in.cue:3:13
-        //     ./in.cue:15:7
         //     ./in.cue:19:3
       }
+      field: (string){ string }
     }
   }
   #Bar: (#struct){
@@ -52,8 +44,8 @@
     field: (int){ int }
   }
   bar: (#struct){
-    field: (int){ int }
     feild: (int){ 2 }
+    field: (int){ int }
   }
   #Mixed: (string){ string }
   Mixed: (string){ string }
-- diff/todo/p2 --
Positions / reordering.
-- out/eval --
Errors:
foo.feild: field not allowed:
    ./in.cue:1:7
    ./in.cue:12:6
    ./in.cue:13:7
foo1.recursive.feild: field not allowed:
    ./in.cue:3:13
    ./in.cue:15:7
    ./in.cue:19:3

Result:
(_|_){
  // [eval]
  #Foo: (#struct){
    field: (int){ int }
    recursive: (#struct){
      field: (string){ string }
    }
  }
  #Foo1: (#struct){
    field: (int){ int }
    field2: (string){ string }
  }
  foo: (_|_){
    // [eval]
    field: (int){ int }
    recursive: (#struct){
      field: (string){ string }
    }
    feild: (_|_){
      // [eval] foo.feild: field not allowed:
      //     ./in.cue:1:7
      //     ./in.cue:12:6
      //     ./in.cue:13:7
    }
  }
  foo1: (_|_){
    // [eval]
    field: (int){ 2 }
    recursive: (_|_){
      // [eval]
      field: (string){ string }
      feild: (_|_){
        // [eval] foo1.recursive.feild: field not allowed:
        //     ./in.cue:3:13
        //     ./in.cue:15:7
        //     ./in.cue:19:3
      }
    }
  }
  #Bar: (#struct){
    field: (int){ int }
  }
  bar: (#struct){
    field: (int){ int }
    feild: (int){ 2 }
  }
  #Mixed: (string){ string }
  Mixed: (string){ string }
  mixedRec: (struct){
    #Mixed: (string){ string }
    Mixed: (string){ string }
  }
}
