-- in.cue --
// All these should pass. These look like recursive inlined calls, but they are
// not.

ok1: {
	f: {
		in:  number
		out: in
	}
	k00: 0
	k10: (f & {in: k00}).out
	k20: (f & {in: k10}).out
	k30: (f & {in: k20}).out
	@test(eq, {
		f: {in: number, out: number}
		k00: 0
		k10: 0
		k20: 0
		k30: 0
	})
}

ok2: {
	f: {
		in:  number
		out: in
	}
	k00: 0
	k10: {(f & {in: k00}).out}
	k20: {(f & {in: k10}).out}
	k30: {(f & {in: k20}).out}
	@test(eq, {
		f: {in: number, out: number}
		k00: 0
		k10: 0
		k20: 0
		k30: 0
	})
}

ok3: {
	f: {
		in:  number
		out: in
	}
	k00: 0
	k10: {close((f & {in: k00})).out}
	k20: {close((f & {in: k10})).out}
	k30: {close((f & {in: k20})).out}
	@test(eq, {
		f: {in: number, out: number}
		k00: 0
		k10: 0
		k20: 0
		k30: 0
	})
}

ok4: {
	f: {
		in:  number
		out: in
	}
	k00: 0
	k10: {out: {(f & {in: k00}).out}}.out
	k20: {out: {(f & {in: k10}).out}}.out
	k30: {out: {(f & {in: k20}).out}}.out
	@test(eq, {
		f: {in: number, out: number}
		k00: 0
		k10: 0
		k20: 0
		k30: 0
	})
}

// Issue #1708: nested indirect selectors on a definition instantiated more than
// twice cause a false structural cycle. Concrete conjuncts like `{in: kN}` are
// not recognized as cycle-breakers, so successive `(#add10 & {in: k}).out`
// chains are incorrectly treated as self-recursive.
// https://cuelang.org/issue/1708
issue1708: {
	#add10: {
		in: number
		a10: { i: in, o: i + 10 }
		out: a10.o
	}
	k00: 0
	k10: (#add10 & {in: k00}).out
	k20: (#add10 & {in: k10}).out
	k30: (#add10 & {in: k20}).out

	@test(eq, {
		#add10: {
			in: number
			a10: {
				i: number
				o: _|_ @test(err, code=incomplete, contains="non-concrete value number in operand to +", pos=[3:20, 2:7])
			}
			out: _|_
		}
		k00: 0
		k10: 10
		k20: 20
		k30: 30
	})
}
-- issue3182.cue --
// evalv3 regression: references under projections (e.g. `{ a: x }.a`) were
// not resolved correctly, producing errors or wrong output that evalv2 handled.
// https://cuelang.org/issue/3182
issue3182: {
	first: t1: {
		x: { a: x }.a
		@test(eq, {x: _})
	}
	first: t2: {
		x: { a: b: x }.a
		@test(err, code=structural_cycle)
	}
	second: {
		{ t: x }.t.y
		x: y: x: y: a: 1
		@test(eq, {x: {y: {x: {y: {a: 1}}, a: 1}}, a: 1})
	}
	third: {
		{
			p: {
			  x: p
			  y: 1
			}
		}.p.x.y
		@test(eq, 1)
	}
}
-- select.cue --
// The value of #Step should be consistent between these test cases.
select: direct: {
	#Step: (#Job & {opt: _}).opt
	#Job: matchN(1, [#NormalJob])
	// TODO(inline): broken generation: retains reference.
	@test(eq, {
		#Step: _
		#Job: matchN(1, [{req!: int, opt?: {run?: string}}])
	})
}
select: indirect: {
	#Step: #Job.opt
	#Job: matchN(1, [#NormalJob]) & {opt: _}
	@test(eq, {#Step: _, #Job: {_|_, opt: _}})
}
#NormalJob: {
	req!: int
	opt?: run?: string
}
-- out/errors.txt --
[incomplete] issue1708.#add10.a10.o: non-concrete value number in operand to +:
    ./in.cue:84:20
    ./in.cue:83:7
[incomplete] issue1708.#add10.a10.o: non-concrete value number in operand to +:
    ./in.cue:84:20
    ./in.cue:83:7
[structural_cycle] issue3182.first.t2.x.b: structural cycle
[incomplete] select.indirect.#Job: invalid value {opt:_} (does not satisfy matchN): 0 matched, expected 1:
    ./select.cue:13:8
    ./select.cue:13:15
select.indirect.#Job.req: field is required but not present:
    ./select.cue:13:8
    ./select.cue:13:19
    ./select.cue:17:2
-- out/todo.txt --
issue1708.k30: evaluates to 30 in v2 but errors (incomplete: undefined field: out) in v3.
issue1708 error positions differ between v2 and v3.
-- out/eval/stats --
Leaks:  1
Freed:  228
Reused: 197
Allocs: 32
Retain: 0

Unifications: 143
Conjuncts:    383
Disjuncts:    0
Notifications: 1

NumCloseIDs: 174
