# Tests that list comprehensions with definitions and nested constraints work.
# Issue #843: complex nested definition with list comprehensions and imports.
-- in.cue --
package main

import "list"

#d1: {
	as: [...string]

	#c: [
		#f1 & {
			"as": list.Concat([["go"], as])
		},
	]
}

#d2: {
	p: *"." | string

	#c: [
		#f2 & {
			from: #d1 & {
				as: [p]
			}
		},
	]
}

#c1: {
	#c: [...#o]
	_
	...
}

#o: #f1 | #f2

#f1: {
	do: "f1"
	as: [...string]
}
#f2: {
	do:   "f2"
	from: #c1
}
-- out/compile --
--- in.cue
{
  #d1: {
    as: [
      ...string,
    ]
    #c: [
      (〈2;#f1〉 & {
        as: 〈import;list〉.Concat([
          [
            "go",
          ],
          〈3;as〉,
        ])
      }),
    ]
  }
  #d2: {
    p: (*"."|string)
    #c: [
      (〈2;#f2〉 & {
        from: (〈3;#d1〉 & {
          as: [
            〈4;p〉,
          ]
        })
      }),
    ]
  }
  #c1: {
    #c: [
      ...〈2;#o〉,
    ]
    _
    ...
  }
  #o: (〈0;#f1〉|〈0;#f2〉)
  #f1: {
    do: "f1"
    as: [
      ...string,
    ]
  }
  #f2: {
    do: "f2"
    from: 〈1;#c1〉
  }
}
