#name: resolved self-reference cycles with disjunction with defaults
#evalPartial
-- in.cue --
// The disjunction in xa could be resolved, but as disjunctions
// are not resolved for expression, it remains unresolved.
xa1: (xa2 & 8) | *(xa4 & 9) @test(eq, 8)
xa2: xa3 + 2 @test(eq, 8)
xa3: 6 & xa1-2 @test(eq, 6)
xa4: xa2 + 2 @test(eq, 10)

// TODO(inline): make positions work here.
xb1: *(xb2 & 8) | (xb4 & 9) @test(err, code=cycle, pos=[],
	suberr=(code=cycle, path=xb2, contains="unresolved disjunction: %v", args=[xb3]),
	suberr=(code=cycle, path=xb3, contains="%d errors in empty disjunction:", args=[3]),
	suberr=(code=cycle, path=xb3, contains="unresolved disjunction: %v", args=[xb1],),
	suberr=(code=cycle, path=xb3, contains="cycle with field: %v", args=[xb2]))
xb2: xb3 + 2 @test(err, code=cycle,
	suberr=(code=cycle, contains="unresolved disjunction: %v", args=[xb3]),
	suberr=(code=cycle, path=xb3, contains="cycle with field: %v", args=[xb2]))
xb3: *(6 & (xb1 - 2)) | (xb4 & 9) @test(err, code=cycle,
	suberr=(code=cycle, path=xb2, contains="unresolved disjunction: %v", args=[xb3]),
	suberr=(code=cycle, contains="unresolved disjunction: %v", args=[xb1]),
	suberr=(code=cycle, contains="cycle with field: %v", args=[xb2]))
xb4: xb2 + 2 @test(err, code=cycle,
	suberr=(code=cycle, path=xb2, contains="unresolved disjunction: %v", args=[xb3]),
	suberr=(code=cycle, path=xb3, contains="cycle with field: %v", args=[xb2]))

// Another variant with more disjunctions. xc1 remains with two
// possibilities. Technically, only the first value is valid.
// However, to fully determine that, all options of the remaining
// disjunction will have to be evaluated algebraically, which is
// not done.
xc1: *(xc2 & 8) | (xc4 & 9) | (xc5 & 9) @test(eq, *8|9)
xc2: xc3 + 2 @test(eq, 8)
xc3: 6 & xc1-2 @test(eq, 6)
xc4: xc2 + 1 @test(eq, 9)
xc5: xc2 + 2 @test(eq, 10)

// The above is resolved by setting xd1 explicitly.
xd1: *(xd2 & 8) | xd4 & 9 | xd5 & 9 @test(eq, *8|9)
xd2: xd3 + 2 @test(eq, 8)
xd3: 6 & xd1-2 @test(eq, 6)
xd4: xd2 + 1 @test(eq, 9)
xd5: xd2 + 2 @test(eq, 10)

// The above is resolved by setting xd1 explicitly to the wrong
// value, resulting in an error.
xe1: *(xe2 & 8) | xe4 & 9 | xe5 & 9
xe2: xe3 + 2 @test(eq, 8)
xe3: 6 & xe1-2 @test(err, code=eval, pos=[0:6, 0:10])
xe4: xe2 + 1 @test(eq, 9)
xe5: xe2 + 2 @test(eq, 10)
xe1: 9 @test(eq, 9)

z1: *(z2 + 1) | z3+5 @test(eq, *11|13)
z2: z3 + 2 @test(eq, 10)
z3: z1 - 3
z3: 8 @test(eq, 8)
-- out/errors.txt --
[cycle] xb1: 4 errors in empty disjunction:
xb2: unresolved disjunction: xb3:
    ./in.cue:14:6
xb3: 3 errors in empty disjunction::
    ./in.cue:14:6
xb3: unresolved disjunction: xb1:
    ./in.cue:17:13
xb3: cycle with field: xb2:
    ./in.cue:21:6
[cycle] xb2: unresolved disjunction: xb3:
    ./in.cue:14:6
xb3: cycle with field: xb2:
    ./in.cue:21:6
[cycle] xb2: unresolved disjunction: xb3:
    ./in.cue:14:6
xb3: 3 errors in empty disjunction::
    ./in.cue:14:6
xb3: unresolved disjunction: xb1:
    ./in.cue:17:13
xb3: cycle with field: xb2:
    ./in.cue:21:6
[cycle] xb2: unresolved disjunction: xb3:
    ./in.cue:14:6
xb3: cycle with field: xb2:
    ./in.cue:21:6
[eval] xe3: conflicting values 7 and 6:
    ./in.cue:47:6
    ./in.cue:47:10
-- out/todo.txt --
xb* cycles: v2 evaluator resolves xb1=8, xb2=8, xb3=*(6|9), xb4=10; v3
correctly identifies cycle errors in xb1-xb4.
-- out/eval/stats --
Leaks:  2
Freed:  42
Reused: 13
Allocs: 31
Retain: 0

Unifications: 27
Conjuncts:    79
Disjuncts:    17

NumCloseIDs: 14
