-- in.cue --
comprehensions: {
	a: {}
	b: {
		if a.b {
		}
	}
	c: {
		for x in a.b {x}
	}
}

openStruct: {
	a: {}
	b: a.c
}

selectFromTop: {
	top: _
	a:   top.foo
}

indexOnTop: {
	top: _
	a:   top[2]
}

incompleteIndex: {
	top: _
	a:   [1][top]
}
-- out/eval/stats --
Leaks:  1
Freed:  17
Reused: 14
Allocs: 4
Retain: 1

Unifications: 18
Conjuncts:    26
Disjuncts:    18
-- out/eval --
Errors:
incompleteIndex.a: invalid index top (invalid type _):
    ./in.cue:29:7
    ./in.cue:29:11

Result:
(_|_){
  // [eval]
  comprehensions: (struct){
    a: (struct){
    }
    b: (_|_){
      // [incomplete] comprehensions.b: undefined field: b:
      //     ./in.cue:4:8
    }
    c: (_|_){
      // [incomplete] comprehensions.c: undefined field: b:
      //     ./in.cue:8:14
    }
  }
  openStruct: (struct){
    a: (struct){
    }
    b: (_|_){
      // [incomplete] openStruct.b: undefined field: c:
      //     ./in.cue:14:7
    }
  }
  selectFromTop: (struct){
    top: (_){ _ }
    a: (_|_){
      // [incomplete] selectFromTop.a: top.foo undefined as top is incomplete (type _):
      //     ./in.cue:19:7
    }
  }
  indexOnTop: (struct){
    top: (_){ _ }
    a: (_|_){
      // [incomplete] indexOnTop.a: top[2] undefined as top is incomplete (type _):
      //     ./in.cue:24:7
    }
  }
  incompleteIndex: (_|_){
    // [eval]
    top: (_){ _ }
    a: (_|_){
      // [eval] incompleteIndex.a: invalid index top (invalid type _):
      //     ./in.cue:29:7
      //     ./in.cue:29:11
    }
  }
}
-- out/compile --
--- in.cue
{
  comprehensions: {
    a: {}
    b: {
      if 〈1;a〉.b {}
    }
    c: {
      for _, x in 〈1;a〉.b {
        〈1;x〉
      }
    }
  }
  openStruct: {
    a: {}
    b: 〈0;a〉.c
  }
  selectFromTop: {
    top: _
    a: 〈0;top〉.foo
  }
  indexOnTop: {
    top: _
    a: 〈0;top〉[2]
  }
  incompleteIndex: {
    top: _
    a: [
      1,
    ][〈0;top〉]
  }
}
