# Tests that comprehensions over intersections of hidden fields work correctly.
# Issue #3762: for comprehensions over _a & _b where both have patterns.
-- in.cue --
full: {
	kube: node: n1: {
		_CL: "l"
		_cs: (_CL): _a[(_CL)]
		_cs: (_CL): {
			opts: {}
		}
	}

	_a: "l": {
		_ba?: string
		opts: {
			if _ba != _|_ {b: (_ba)}
		}
	}

	for k, _ in _a & _b {
		x: 5
	}

	_a: [ID=_]: vms: [{ name: "hello" }]
	_b: [ID=_]: vms: [{ name: "again" }]
	@test(eq, {
		kube: node: n1: {
			_CL: "l"
			_cs: l: {
				opts: {}
				_ba?: string
				vms: [{
					name: "hello"
				}]
			}
		}
		_a: l: {
			_ba?: string
			opts: {}
			vms: [{
				name: "hello"
			}]
		}
		x: 5
		_b: {}
	})
}
reduced: p1: {
	_cs: _a.l & {
		opts: {}
	}

	_a: l: {
		_ba?: string
		opts: {
			if _ba != _|_ {
				b: _ba
			}
		}
		vms: "hello"
	}

	_b: l: vms: "again"

	for k, _ in _a & _b {
		x: 5
	}
	@test(eq, {
		_cs: {opts: {}, _ba?: string, vms: "hello"}
		_a: {
			l: {_ba?: string, opts: {}, vms: "hello"}
		}
		_b: {l: {vms: "again"}}
		x: 5
	})
}
reduced: p2: {
	for k, _ in _a & _b {
		x: 5
	}

	_cs: _a.l & {
		opts: {}
	}

	_a: l: {
		_ba?: string
		opts: {
			if _ba != _|_ {
				b: _ba
			}
		}
		vms: "hello"
	}

	_b: l: vms: "again"
	@test(eq, {
		x: 5
		_cs: {opts: {}, _ba?: string, vms: "hello"}
		_a: {
			l: {_ba?: string, opts: {}, vms: "hello"}
		}
		_b: {l: {vms: "again"}}
	})
}
reference: {
	_x: {
		f: true
	}

	_y: {
		f: false
	}

	for k, _ in _x & _y {
		ok: true
	}
	@test(eq, {
		_x: {f: true}
		_y: {f: false}
		ok: true
	})
}
-- out/eval/stats --
Leaks:  6
Freed:  74
Reused: 55
Allocs: 25
Retain: 0

Unifications: 71
Conjuncts:    101
Disjuncts:    0
Notifications: 8

NumCloseIDs: 25
