# evalv3 incorrectly reported "operand of '!' not concrete" for a generator
# pattern where a dynamic field key depends on a unified struct, and a
# comprehension over a non-existent list field is reachable only via an
# indirect unification. The bug only reproduced with a builtin call
# (strings.HasPrefix) feeding the '!' operator, and required the extra
# {extra: unused: "unused"} unification to trigger.
# https://cuelang.org/issue/4094
-- in.cue --
import "strings"

_libexport: {
	_OBJECTS: {...}
	_IMPORTS: [...]
	_GENERATORS: [...]

	_generated_objects: [
		for _, obj in _OBJECTS
		for _, gen in _GENERATORS
		for _, o in (gen & {_input: obj})._output {o},
	]

	_imported_objects: [
		for _, import in _IMPORTS
		for _, obj in ({extra: unused: "unused"} & import).export.objects {obj},
	]

	objects: [
		for _, obj in _OBJECTS {obj},
		for _, obj in _generated_objects {obj},
		for _, obj in _imported_objects {obj},
	]
}
export: _libexport & {
	_IMPORTS: [_imported]
} @test(eq, at=objects, [
	{_neverTrue: false, alwaysSet: "foo", name: "name1", spec: {image: "image1"}},
	{generated: true},
])

_imported: {
	export: _libexport & {
		_OBJECTS: objects
		_GENERATORS: [_Service]
	}

	objects: [KIND=string]: {
		_neverTrue: strings.HasPrefix(KIND, "NEVER")
		if !_neverTrue {
			alwaysSet: "foo"
		}
	}
	objects: deployment: {
		name: "name1"
		spec: image: "image1"
	}
}
_Service: {
	_input: {...}

	for _, image in [_input.spec.image] {}

	_service: (_input.name): generated: true
	_output: [for _, svc in _service {svc}]
}
-- out/errors.txt --
[incomplete] _Service._service: key value of dynamic field must be concrete, found _|_(_Service._service: undefined field: name):
    ./in.cue:54:13
_Service._service: undefined field: name:
    ./in.cue:54:20
[incomplete] _Service._service: key value of dynamic field must be concrete, found _|_(_Service._service: undefined field: name):
    ./in.cue:54:13
_Service._service: undefined field: name:
    ./in.cue:54:20
-- out/eval/stats --
Leaks:  15
Freed:  115
Reused: 76
Allocs: 54
Retain: 0

Unifications: 110
Conjuncts:    205
Disjuncts:    0
Notifications: 8

NumCloseIDs: 85
