# A CUE file using comprehensions and struct embeddings that exports
# successfully in v0.13.2 fails with "undefined field" in later versions.
# https://cuelang.org/issue/4203
-- in.cue --
import "strings"

// Marking comprehension fields as optional for cycle detection
// should not prevent fixed fields from being resolved.
_listBuilder: {
	kind: "kind1"
	_deps: [...]
	_kindJoin: {
		_objs: [...]
		_out: strings.Join([for d in _objs {d.kind}], ",")
	}
	_depKinds: {_kindJoin & {_objs: _deps}}._out
	variable: "{" + _depKinds + "}"
}

output: _
if true {
	_input: [{
		_listBuilder
		_deps: [{_listBuilder}]
	}]

	output: _input[0].variable
}
-- out/compile --
--- in.cue
{
  _listBuilder: {
    kind: "kind1"
    _deps: [
      ...,
    ]
    _kindJoin: {
      _objs: [
        ...,
      ]
      _out: 〈import;strings〉.Join([
        for _, d in 〈1;_objs〉 {
          〈1;d〉.kind
        },
      ], ",")
    }
    _depKinds: {
      (〈1;_kindJoin〉 & {
        _objs: 〈2;_deps〉
      })
    }._out
    variable: (("{" + 〈0;_depKinds〉) + "}")
  }
  output: _
  if true {
    _input: [
      {
        〈3;_listBuilder〉
        _deps: [
          {
            〈5;_listBuilder〉
          },
        ]
      },
    ]
    output: 〈0;_input〉[0].variable
  }
}
