-- references.cue --
missingField: {
	a: {}
	r: a.b
}

missingFieldClosed: {
	#a: {}
	r: #a.b
}

missingFieldNested: {
	a: {}
	// Must refer to `b` in error
	r: a.b.c
}

missingFieldNestedClosed: {
	#a: {}

	// Must refer to `d` in error
	r: #a.d.c
}

missingFieldNestedInInterpolation: {
	a: {}
	// Must refer to `b` in error
	r1: "\(a.b.c)"
	// Must refer to `d` in error: in case only one error is shown for a
	// a location, ensure it doesn't alphabetically sort and pick `c` instead.
	r2: "\(a.d.c)"
}
-- out/eval/stats --
Leaks:  0
Freed:  17
Reused: 14
Allocs: 3
Retain: 0

Unifications: 17
Conjuncts:    29
Disjuncts:    17
-- out/eval --
Errors:
missingFieldClosed.r: undefined field: b:
    ./references.cue:8:8
missingFieldNestedClosed.r: undefined field: d:
    ./references.cue:21:8

Result:
(_|_){
  // [eval]
  missingField: (struct){
    a: (struct){
    }
    r: (_|_){
      // [incomplete] missingField.r: undefined field: b:
      //     ./references.cue:3:7
    }
  }
  missingFieldClosed: (_|_){
    // [eval]
    #a: (#struct){
    }
    r: (_|_){
      // [eval] missingFieldClosed.r: undefined field: b:
      //     ./references.cue:8:8
    }
  }
  missingFieldNested: (struct){
    a: (struct){
    }
    r: (_|_){
      // [incomplete] missingFieldNested.r: undefined field: b:
      //     ./references.cue:14:7
    }
  }
  missingFieldNestedClosed: (_|_){
    // [eval]
    #a: (#struct){
    }
    r: (_|_){
      // [eval] missingFieldNestedClosed.r: undefined field: d:
      //     ./references.cue:21:8
    }
  }
  missingFieldNestedInInterpolation: (struct){
    a: (struct){
    }
    r1: (_|_){
      // [incomplete] missingFieldNestedInInterpolation.r1: invalid interpolation: undefined field: b:
      //     ./references.cue:27:6
      //     ./references.cue:27:11
    }
    r2: (_|_){
      // [incomplete] missingFieldNestedInInterpolation.r2: invalid interpolation: undefined field: d:
      //     ./references.cue:30:6
      //     ./references.cue:30:11
    }
  }
}
-- out/compile --
--- references.cue
{
  missingField: {
    a: {}
    r: 〈0;a〉.b
  }
  missingFieldClosed: {
    #a: {}
    r: 〈0;#a〉.b
  }
  missingFieldNested: {
    a: {}
    r: 〈0;a〉.b.c
  }
  missingFieldNestedClosed: {
    #a: {}
    r: 〈0;#a〉.d.c
  }
  missingFieldNestedInInterpolation: {
    a: {}
    r1: "\(〈0;a〉.b.c)"
    r2: "\(〈0;a〉.d.c)"
  }
}
