-- in.cue --
a: b - 100 @test(err, code=cycle)
b: a + 100 @test(err, code=cycle)

c: [c[1], c[0]] @test(eq, [_, _])

d: e - 1 @test(eq, 1)
e: 1 + d
e: *2 | 0 @test(eq, *2 | 0)
-- disjunction.cue --
oneway: {
    t1: {
        a: *1 | int
        a: b + 1
        b: <a
        @test(eq, {
			a: _|_ @test(err, code=cycle, contains="cycle with field: b", pos=[2:12])
			b: _|_ @test(err, code=cycle, contains="cycle with field: b", pos=[2:12])
		})
    }
    t2: t1 &{
        a: 3
    } @test(eq, {
		a: _|_ @test(err, code=incomplete, contains="non-concrete value <3 in operand to +", pos=[-7:12, -6:12])
		b: <3
	})
}
// This should report a cycle error. TODO: this should also resolve.
issue3669: {
	#Schema: {
		two: 1 + one
		one: two - 1
	}

	out: #Schema & {
		two: 0 | *2
	}
	@test(eq, {
		#Schema: {
			two: _|_ @test(err, code=cycle, contains="issue3669.#Schema.one: cycle with field: two (and 1 more errors)", pos=[3:8])
			one: _|_ @test(err, code=cycle, contains="issue3669.#Schema.one: cycle with field: two (and 1 more errors)", pos=[3:8])
		}
		out: {
			two: _|_
			one: _|_ @test(err, code=cycle, contains="cycle with field: one", pos=[2:12])
		}
	})
}
-- issue3737.cue --
// Apparent cycle issue in evalv3 when combining a definition with a default
// disjunction and a derived field value.
// https://cuelang.org/issue/3737
issue3737: reduced1: {
    #A: {
        a: b * 12
        b: a / 12
    }

    x: #A
    x: b: 1000.0

    y: #A | *x
    y: b: x.b * 0.7
    @test(eq, {
			#A: {
				a: _|_ @test(err, code=cycle,
					contains="reduced1.#A.b: cycle with field: a (and 1 more errors)", pos=[3:12])
				b: _|_ @test(err, code=cycle,
					contains="reduced1.#A.b: cycle with field: a (and 1 more errors)", pos=[3:12])
		}
		x: {b: 1000.0, a: 12000.0}
		y: {b: 700.00, a: 8400.00}
	})
}
issue3737: reduced2: {
    x: #TimeSpan & {
        start: y.start
        end: 1000.0
    }
    y: #TimeSpan & {
        duration: 100.0
        end: x.end
    }
    #TimeSpan: {
        start:    end - duration
        duration: end - start
        end:      start + duration
    }
    @test(eq, {
		x: {
			start: 900.0
			end: 1000.0
			duration: 100.0
		}
		y: {
			duration: 100.0
			end: 1000.0
			start: 900.0
		}
		#TimeSpan: {
			start: _|_ @test(err, code=cycle,
				contains="reduced2.#TimeSpan.end: cycle with field: start (and 2 more errors)", pos=[12:19])
			duration: _|_ @test(err, code=cycle,
				contains="reduced2.#TimeSpan.start: cycle with field: end (and 2 more errors)", pos=[10:19])
			end: _|_ @test(err, code=cycle, 
				contains="reduced2.#TimeSpan.start: cycle with field: end (and 2 more errors)", pos=[10:19])
		}
	})
}
-- out/errors.txt --
[cycle] oneway.t1.a: cycle with field: b:
    ./disjunction.cue:4:12
oneway.t1.b: cycle with field: a:
    ./disjunction.cue:5:13
[cycle] oneway.t1.a: cycle with field: b:
    ./disjunction.cue:4:12
oneway.t1.b: cycle with field: a:
    ./disjunction.cue:5:13
[incomplete] oneway.t2.a: 2 errors in empty disjunction:
oneway.t2.a: conflicting values 1 and 3:
    ./disjunction.cue:3:13
    ./disjunction.cue:11:9
    ./disjunction.cue:12:12
oneway.t2.a: non-concrete value <3 in operand to +:
    ./disjunction.cue:4:12
    ./disjunction.cue:5:12
[cycle] issue3669.#Schema.two: cycle with field: one:
    ./disjunction.cue:21:12
issue3669.#Schema.one: cycle with field: two:
    ./disjunction.cue:22:8
[cycle] issue3669.#Schema.two: cycle with field: one:
    ./disjunction.cue:21:12
issue3669.#Schema.one: cycle with field: two:
    ./disjunction.cue:22:8
[cycle] issue3669.out.two: cycle with field: one:
    ./disjunction.cue:21:12
issue3669.out.one: cycle with field: two:
    ./disjunction.cue:22:8
[cycle] issue3669.out.two: cycle with field: one:
    ./disjunction.cue:21:12
issue3669.out.one: cycle with field: two:
    ./disjunction.cue:22:8
[cycle] a: cycle with field: b:
    ./in.cue:1:4
b: cycle with field: a:
    ./in.cue:2:4
[cycle] a: cycle with field: b:
    ./in.cue:1:4
b: cycle with field: a:
    ./in.cue:2:4
[cycle] issue3737.reduced1.#A.a: cycle with field: b:
    ./issue3737.cue:6:12
issue3737.reduced1.#A.b: cycle with field: a:
    ./issue3737.cue:7:12
[cycle] issue3737.reduced1.#A.a: cycle with field: b:
    ./issue3737.cue:6:12
issue3737.reduced1.#A.b: cycle with field: a:
    ./issue3737.cue:7:12
[cycle] issue3737.reduced2.#TimeSpan.start: cycle with field: end:
    ./issue3737.cue:36:19
issue3737.reduced2.#TimeSpan.end: cycle with field: start:
    ./issue3737.cue:38:19
issue3737.reduced2.#TimeSpan.end: cycle with field: duration:
    ./issue3737.cue:38:27
[cycle] issue3737.reduced2.#TimeSpan.start: cycle with field: end:
    ./issue3737.cue:36:19
issue3737.reduced2.#TimeSpan.end: cycle with field: start:
    ./issue3737.cue:38:19
issue3737.reduced2.#TimeSpan.end: cycle with field: duration:
    ./issue3737.cue:38:27
[cycle] issue3737.reduced2.#TimeSpan.start: cycle with field: end:
    ./issue3737.cue:36:19
issue3737.reduced2.#TimeSpan.end: cycle with field: start:
    ./issue3737.cue:38:19
issue3737.reduced2.#TimeSpan.end: cycle with field: duration:
    ./issue3737.cue:38:27
-- out/todo.txt --
oneway.t1.b: success (<1) in v2 but cycle error in v3.
issue3669.out.one: success (-1) in v2 but cycle error in v3.
d/e: cycle error in v2 but success (1 and *(2)|0) in v3.
issue3737.reduced1.x: a before b in v2, b before a in v3.
issue3737.reduced2.x/y: field ordering differs between v2 and v3.
-- out/eval/stats --
Leaks:  5
Freed:  54
Reused: 34
Allocs: 25
Retain: 0

Unifications: 47
Conjuncts:    91
Disjuncts:    10

NumCloseIDs: 10
