# Tests that inner structs within a definition template constraint are not
# incorrectly treated as closed when unified via a non-definition value.
# https://cuelang.org/issue/359
-- in.cue --
#simple: {
	peso: *1 | int
	edad: *2 | int
}

// Second struct is not considered closed, as expected
good: #simple & {
	peso: 4
} @test(eq, {peso: 4, edad: *2 | int})

#complex: {
	things: [string]: #simple
}

// Still, no closedness issue in the second struct
#many: #complex & {
	things: hola: peso: 2
	things: sol: peso:  3
} @test(eq, {
	things: {
		hola: {
			peso: 2
			edad: *2 | int
		}
		sol: {
			peso: 3
			edad: *2 | int
		}
	}
})

// Inner struct in second struct IS considered closed: why?
bad: #many & {
	things: hola: peso: 2
} @test(eq, {
	things: {
		hola: {
			peso: 2
			edad: *2 | int
		}
		sol: {
			peso: 3
			edad: *2 | int
		}
	}
})

// non-definition equivalent
many: #complex & {
	things: hola: peso: 2
	things: sol: peso:  3
} @test(eq, {
	things: {
		hola: {
			peso: 2
			edad: *2 | int
		}
		sol: {
			peso: 3
			edad: *2 | int
		}
	}
})

// Now inner struct on second struct is NOT considered closed
notbad: many & {
	things: hola: peso: 2
} @test(eq, {
	things: {
		hola: {
			peso: 2
			edad: *2 | int
		}
		sol: {
			peso: 3
			edad: *2 | int
		}
	}
})
-- out/eval/stats --
Leaks:  9
Freed:  72
Reused: 57
Allocs: 24
Retain: 0

Unifications: 41
Conjuncts:    134
Disjuncts:    40

NumCloseIDs: 15
