# `a: [rn=string]: _Q[0:len(a[rn])]` silently produces wrong output: `a.ben`
# should be `[{pos: 0}]` (a one-element slice matching the concrete entry's
# length) but instead produces `[{}]` with `pos` missing and no error reported.
# The equivalent closed-type pattern `#d: [rn=string]: [...] & _Q[0:len(#d[rn])]`
# works correctly. The self-referential slice constraint is not being unified.
# https://cuelang.org/issue/494
-- in.cue --
_Q: [{pos: 0}, {pos: 1}]

a: [rn=string]: _Q[0:len(a[rn])]
a: ben: [{}] @test(eq, [{pos: 0}])

b: [rn=string]: _Q[0:1]
b: ben: [{}] @test(eq, [{pos: 0}])

c: [rn=string]: [...{l: len(a[rn])}]
c: ben: [{}] @test(eq, [{l: 1}])

#d: [rn=string]: [...{pos: uint}] & _Q[0:len(#d[rn])]
#d: ben: [{}] @test(eq, [{pos: 0}])

d: #d @test(eq, {ben: [{pos: 0}]})

e: [rn=string]: _Q[0 : len(a[rn])+1]
e: ben: [{}, ...] @test(eq, [{pos: 0}, {pos: 1}])

f: [rn=string]: _Q[0 : len(a[rn])+1]
f: ben: [{}] @test(err, code=eval, contains="incompatible list lengths", pos=[])

g: [rn=string]: _Q[0:len(a[rn])]
g: ben: [{}, {}] @test(err, code=eval, contains="incompatible list lengths", pos=[])
-- out/errors.txt --
[eval] f.ben: incompatible list lengths (1 and 2)
[eval] g.ben: incompatible list lengths (1 and 2)
-- out/todo.txt --
v2 expands `d` into an independent struct; v3 shares the same vertex as `#d` (d: ~(#d)).
v2 includes extra sub-fields pos values in f.ben and g.ben error output.
-- out/eval/stats --
Leaks:  0
Freed:  36
Reused: 22
Allocs: 14
Retain: 0

Unifications: 36
Conjuncts:    59
Disjuncts:    0
