# evalv3 incorrectly reports a structural cycle error for a CUE definition that
# validates correctly under evalv2, representing a regression in cycle detection.
# https://cuelang.org/issue/3571
-- in.cue --
// These tests should NOT have structural cycles.
simplified: {
	#T
	in: _
	x: #T
	x: x: #T

	#T: {
		in: x
		x: _
	}

	@test(eq, {
		in: {x: {in: _, x: _}, in: {in: _, x: _}}
		x: {x: {in: _, x: _}, in: {in: _, x: _}}
		#T: {in: _, x: _}
	})
}

issue3571: {
	a: #T
	a: in: f: true
	a: #in: {
		g: #T
		g: #in: f: #T
		g: #in: f: #in: x: true
		f?: _
	}

	#T: {
		in:  #in
		#in: _
	}

	@test(eq, {
		a: {
			in: {
				f: true
				g: {
					#in: {f: {#in: {x: true}, in: {x: true}}}
					in: {f: {#in: {x: true}, in: {x: true}}}
				}
			}
			#in: {
				g: {
					#in: {f: {#in: {x: true}, in: {x: true}}}
					in: {f: {#in: {x: true}, in: {x: true}}}
				}
				f?: _
			}
		}
		#T: {in: _, #in: _}
	})
}
-- out/eval/stats --
Leaks:  0
Freed:  34
Reused: 19
Allocs: 15
Retain: 0

Unifications: 34
Conjuncts:    70
Disjuncts:    0
Notifications: 1

NumCloseIDs: 12
-- out/todo.txt --
v2 expands all structure-shared fields inline (no ~() references), while v3
uses structure sharing (~(path) notation) for fields that share the same
underlying vertex. Specifically, in `simplified`, v2 expands `in` and `x`
with their full #T contents, while v3 represents them as ~(simplified.#T).
Similarly in `issue3571.a`, v2 expands `in` and `#in` fully, while v3 uses
shared references like ~(issue3571.a.in.g.#in) and ~(issue3571.a.#in.g.#in).
