# evalv3 incorrectly reported a "cyclic reference to field" error when a
# comprehension-based field (_volumes) was conditionally exposed (volumes)
# and then referenced through a generator pattern that re-binds the struct
# via {_input: _obj}.
# https://cuelang.org/issue/4091
-- in.cue --
output: (_Generator & {_input: _obj})._output @test(eq, {
	genID: "id1"
	_id: "id1"
	volumeMounts: [{name: "mount1"}]
	_volumes: {mount1: {name: "mount1"}}
	volumes: {mount1: {name: "mount1"}}
})

_obj: spec: {
	_id: "id1"
	volumeMounts: [{name: "mount1"}]
	_volumes: {
		for _, vm in spec.volumeMounts {
			(vm.name): name: vm.name
		}
	}
	if len(_volumes) > 0 {
		volumes: _volumes
	}
}
_Generator: {
	_input: {...}
	_output: _input.spec
	if _input.spec._id != _|_ {
		_output: genID: (_input.spec._id)
	}
}
-- out/errors.txt --
[incomplete] _Generator._output: undefined field: spec:
    ./in.cue:23:18
-- out/eval/stats --
Leaks:  1
Freed:  36
Reused: 13
Allocs: 24
Retain: 0

Unifications: 34
Conjuncts:    49
Disjuncts:    0

NumCloseIDs: 19
