exec cue eval ./pkg:foo

-- cue.mod/module.cue --
module: "mod.test"
language: version: "v0.9.0"
-- in.cue --
package foo

import "mod.test/pkg"

#def: {
	_name: d: int
}

d: pkg.#D & {_name: d: int, _val: f: 4}

// TODO: this should fail, as the _name restricting it is in this
// package.
e: pkg.#D & #def & {
	// This should fail as c is disallowed by the _name defined
	// in this package
	_name: c: int

	// This should not fail, as this is a different _val
	_val: g: int
}

f: pkg.#D & {_val: f: 4}
g: f._val
-- pkg/bar.cue --
package pkg

#D: {_val: f: 3}
-- out/eval/stats --
Leaks:  1
Freed:  29
Reused: 24
Allocs: 6
Retain: 2

Unifications: 30
Conjuncts:    40
Disjuncts:    31
-- out/evalalpha --
Errors:
e._name.c: field not allowed:
    ./in.cue:16:9

Result:
(_|_){
  // [eval]
  #def: (#struct){
    _name(:foo): (#struct){
      d: (int){ int }
    }
  }
  d: (#struct){
    _name(:foo): (struct){
      d: (int){ int }
    }
    _val(:foo): (struct){
      f: (int){ 4 }
    }
    _val(mod.test/pkg): (#struct){
      f: (int){ 3 }
    }
  }
  e: (_|_){
    // [eval]
    _name(:foo): (_|_){
      // [eval]
      c: (_|_){
        // [eval] e._name.c: field not allowed:
        //     ./in.cue:16:9
      }
      d: (int){ int }
    }
    _val(:foo): (struct){
      g: (int){ int }
    }
    _val(mod.test/pkg): (#struct){
      f: (int){ 3 }
    }
  }
  f: (#struct){
    _val(:foo): (struct){
      f: (int){ 4 }
    }
    _val(mod.test/pkg): (#struct){
      f: (int){ 3 }
    }
  }
  g: ~(f._val(:foo))
}
-- diff/-out/evalalpha<==>+out/eval --
diff old new
--- old
+++ new
@@ -1,7 +1,5 @@
 Errors:
 e._name.c: field not allowed:
-    ./in.cue:6:9
-    ./in.cue:13:13
     ./in.cue:16:9
 
 Result:
@@ -13,9 +11,6 @@
     }
   }
   d: (#struct){
-    _val(mod.test/pkg): (#struct){
-      f: (int){ 3 }
-    }
     _name(:foo): (struct){
       d: (int){ int }
     }
@@ -22,35 +17,34 @@
     _val(:foo): (struct){
       f: (int){ 4 }
     }
+    _val(mod.test/pkg): (#struct){
+      f: (int){ 3 }
+    }
   }
   e: (_|_){
     // [eval]
-    _val(mod.test/pkg): (#struct){
-      f: (int){ 3 }
-    }
     _name(:foo): (_|_){
       // [eval]
-      d: (int){ int }
       c: (_|_){
         // [eval] e._name.c: field not allowed:
-        //     ./in.cue:6:9
-        //     ./in.cue:13:13
         //     ./in.cue:16:9
       }
+      d: (int){ int }
     }
     _val(:foo): (struct){
       g: (int){ int }
     }
+    _val(mod.test/pkg): (#struct){
+      f: (int){ 3 }
+    }
   }
   f: (#struct){
-    _val(mod.test/pkg): (#struct){
-      f: (int){ 3 }
-    }
-    _val(:foo): (struct){
-      f: (int){ 4 }
-    }
-  }
-  g: (struct){
-    f: (int){ 4 }
-  }
+    _val(:foo): (struct){
+      f: (int){ 4 }
+    }
+    _val(mod.test/pkg): (#struct){
+      f: (int){ 3 }
+    }
+  }
+  g: ~(f._val(:foo))
 }
-- diff/todo/p2 --
Reordering / missing positions.
-- out/eval --
Errors:
e._name.c: field not allowed:
    ./in.cue:6:9
    ./in.cue:13:13
    ./in.cue:16:9

Result:
(_|_){
  // [eval]
  #def: (#struct){
    _name(:foo): (#struct){
      d: (int){ int }
    }
  }
  d: (#struct){
    _val(mod.test/pkg): (#struct){
      f: (int){ 3 }
    }
    _name(:foo): (struct){
      d: (int){ int }
    }
    _val(:foo): (struct){
      f: (int){ 4 }
    }
  }
  e: (_|_){
    // [eval]
    _val(mod.test/pkg): (#struct){
      f: (int){ 3 }
    }
    _name(:foo): (_|_){
      // [eval]
      d: (int){ int }
      c: (_|_){
        // [eval] e._name.c: field not allowed:
        //     ./in.cue:6:9
        //     ./in.cue:13:13
        //     ./in.cue:16:9
      }
    }
    _val(:foo): (struct){
      g: (int){ int }
    }
  }
  f: (#struct){
    _val(mod.test/pkg): (#struct){
      f: (int){ 3 }
    }
    _val(:foo): (struct){
      f: (int){ 4 }
    }
  }
  g: (struct){
    f: (int){ 4 }
  }
}
-- out/compile --
--- in.cue
{
  #def: {
    _name: {
      d: int
    }
  }
  d: (〈import;"mod.test/pkg"〉.#D & {
    _name: {
      d: int
    }
    _val: {
      f: 4
    }
  })
  e: ((〈import;"mod.test/pkg"〉.#D & 〈0;#def〉) & {
    _name: {
      c: int
    }
    _val: {
      g: int
    }
  })
  f: (〈import;"mod.test/pkg"〉.#D & {
    _val: {
      f: 4
    }
  })
  g: 〈0;f〉._val
}
