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
}  @test(err, code=eval, at=_name$foo.c, contains="field not allowed", pos=[3:9])

f: pkg.#D & {_val: f: 4} @test(debugCheck, """
	(#struct){
	  _val(:foo): (struct){
	    f: (int){ 4 }
	  }
	  _val(mod.test/pkg): (#struct){
	    f: (int){ 3 }
	  }
	}
	""")

g: f._val @test(eq, {f: 4})
-- pkg/bar.cue --
package pkg

#D: {_val: f: 3}
-- out/errors.txt --
[eval] e._name.c: field not allowed:
    ./in.cue:16:9
-- out/eval/stats --
Leaks:  2
Freed:  25
Reused: 14
Allocs: 13
Retain: 0

Unifications: 26
Conjuncts:    35
Disjuncts:    0

NumCloseIDs: 4
-- out/diff-v2-v3.txt --
g: v2 evaluator expands g to {f: 4}; v3 uses structure sharing (~(f._val(:foo))).
Verdict: improvement -- v3 uses structure sharing for g; more efficient.
