// Lots of cycle-reference goodness.
# Tests that pattern constraints on cyclically-referenced fields do not
# cause infinite evaluation. Also tests issue3326 (cyclic pattern constraints).
-- in.cue --
[!~"^[.]"]: c
a:          b
b: [string]: int
c: a:        int
[string]: c
a:        b      @test(eq, {a: int})
b: [string]: int
c: a:        int @test(eq, int)

-- issue3326.cue --
// https://cuelang.org/issue/3326
issue3326: {
	// This issue triggered a cyclic evaluation in pattern constraints.
	//
	// It seems like there is still an issue as the evaluation of `x` in
	// `and` may trigger a cyclic evaluation of `and`. However, `and` only
	// does a shallow evaluation, and inserting `x`'s conjuncts into itself
	// is identified as idempotent and thus further evaluation is skipped.
	_self: x: [...and(x)]
	_self
	x: [1]
	@test(eq, {_self: {x: []}, x: [1], a: int})
}
-- out/todo.txt --
issue3326 is present in v3 (evalalpha) but not in v2 (eval) — v2 did not evaluate it.
-- out/eval/stats --
Leaks:  0
Freed:  13
Reused: 4
Allocs: 9
Retain: 0

Unifications: 13
Conjuncts:    53
Disjuncts:    0
Notifications: 1

NumCloseIDs: 7
