# Tests that closedness is correctly propagated through multiple levels of
# embedded definitions with optional fields and conditional comprehensions.
# #Leaf embeds #Mid (which embeds #Base), all with optional fields. The nested
# if comprehensions inside #Leaf reference optional fields without triggering
# spurious closedness errors.
-- in.cue --
object: #Leaf & {} @test(eq, {extra?: {}, more?: int}) @test(closed)

#Base: {
	extra?: {...}
	@test(eq, {extra?: {}})
	@test(closed)
}

#Mid: {
	#Base
	@test(eq, {extra?: {}})
	@test(closed)
}

#Leaf: {
	#Mid
	extra?:  {...}
	more?: int
	if extra.foo != _|_ {
		if more != _|_ {
			foo: "bar"
		}
	}
	@test(eq, {extra?: {}, more?: int})
	@test(closed)
}
-- out/eval/stats --
Leaks:  0
Freed:  11
Reused: 5
Allocs: 6
Retain: 7

Unifications: 11
Conjuncts:    25
Disjuncts:    18

NumCloseIDs: 2
