# Stack overflow when multiple `!=` constraints are applied between fields
# in a structural cycle involving a disjunction (e.g. a grid where each cell
# must differ from its neighbors).
# https://cuelang.org/issue/242
-- in.cue --
#size:     2
#CellValue: 0 | 1 | 2 | 3
cell: "0": "0": #CellValue
cell: "0": "0": !=cell["0"]["1"]
cell: "0": "0": !=cell["1"]["0"]
cell: "0": "0": !=cell["1"]["1"]

cell: "0": "1": #CellValue
cell: "0": "1": !=cell["0"]["0"]
cell: "0": "1": !=cell["1"]["0"]
cell: "0": "1": !=cell["1"]["1"]

cell: "1": "0": #CellValue
cell: "1": "0": !=cell["0"]["0"]
cell: "1": "0": !=cell["0"]["1"]
cell: "1": "0": !=cell["1"]["1"]

cell: "1": "1": #CellValue
cell: "1": "1": !=cell["0"]["0"]
cell: "1": "1": !=cell["0"]["1"]
cell: "1": "1": !=cell["1"]["0"]

cell: "0": "0": 0
cell: "0": "1": 1
cell: "1": "0": 2
cell: "1": "1": 3
@test(eq, {
	"0": {"0": 0, "1": 1}
	"1": {"0": 2, "1": 3}
}, at=cell)

cell2: a: 0 | 1
cell2: a: !=cell2.b

cell2: b: 0 | 1
cell2: b: !=cell2.a

cell2: a: _
cell2: b: 1
@test(eq, {a: 0, b: 1}, at=cell2)

cell3: a: 0 | 1
cell3: a: !=cell3.b

cell3: b: 0 | 1
cell3: b: !=cell3.a

cell3: a: 0
cell3: b: _
@test(eq, {a: 0, b: 1}, at=cell3)

cell4: a: 0 | 1
cell4: a: !=cell4.b

cell4: b: 0 | 1
cell4: b: !=cell4.a

cell4: b: _
cell4: a: 0

cell5: b: 0 | 1
cell5: b: !=cell5.a

cell5: a: 0 | 1
cell5: a: !=cell5.b

cell5: b: _
cell5: a: 0

a: #CellValue
a: !=b
a: !=c
a: !=d

b: #CellValue
b: !=a
b: !=c
b: !=d

c: #CellValue
c: !=a
c: !=b
c: !=d

d: #CellValue
d: !=a
d: !=b
d: !=c

a: 0
b: 1
c: 2
d: 3
-- out/eval/stats --
Leaks:  16
Freed:  62
Reused: 50
Allocs: 28
Retain: 0

Unifications: 26
Conjuncts:    191
Disjuncts:    52

NumCloseIDs: 8
