# Tests field visibility and comprehension iteration: comprehensions only iterate
# regular (non-optional, non-hidden, non-definition) fields; select and index access
# have different rules for optional, hidden, and definition fields. Issue #94.
-- in.cue --
foo: {
	opt?:    1
	"txt":   2
	#def:    3
	regular: 4
	_hidden: 5
	@test(eq, {opt?: 1, txt: 2, #def: 3, regular: 4, _hidden: 5})
}
comp: { for k, v in foo {"\(k)": v} } @test(eq, {txt: 2, regular: 4})
select: {
	opt:     foo.opt     @test(err, code=incomplete, contains="cannot reference optional field", pos=[0:15])
	"txt":   foo.txt     @test(eq, 2)
	#def:    foo.#def    @test(eq, 3)
	regular: foo.regular @test(eq, 4)
	_hidden: foo._hidden @test(eq, 5)
}
index: {
	opt:     foo["opt"]     @test(err, code=incomplete, contains="cannot reference optional field", pos=[0:15])
	"txt":   foo["txt"]     @test(eq, 2)
	#def:    foo["#def"]    @test(err, code=incomplete, contains="undefined field", pos=[0:15])
	regular: foo["regular"] @test(eq, 4)
	_hidden: foo["_hidden"] @test(err, code=incomplete, contains="undefined field", pos=[0:15])
}
-- out/errors.txt --
[incomplete] select.opt: cannot reference optional field: opt:
    ./in.cue:11:15
[incomplete] index.opt: cannot reference optional field: opt:
    ./in.cue:18:15
[incomplete] index.#def: undefined field: "#def":
    ./in.cue:20:15
[incomplete] index._hidden: undefined field: "_hidden":
    ./in.cue:22:15
-- out/eval/stats --
Leaks:  0
Freed:  22
Reused: 19
Allocs: 3
Retain: 0

Unifications: 22
Conjuncts:    32
Disjuncts:    22

MisalignedConjunct: 1

NumCloseIDs: 1
