-- in.cue --
import "encoding/yaml"

// issue3972: Tests that yaml.Marshal with list comprehensions over conditionally
// defined fields works correctly in evalv3. https://cuelang.org/issue/3972
issue3972: {
	// yaml uses Syntax to convert CUE to YAML. Ensure that unresolved values
	// are properly handled.
	// TODO(inline): the inline testing framework indicated that this field
	// was not used in the computation of the test result. That seems correct.
	// But maybe this test is then not testing what it is supposed to do.
	// Investigate against the original issue.
	output: out0: "static" // has to go first

	input: inputStatic: "static"
	if false {
		input: inputNever: "never"
	}

	derived: derivedStatic: "static"
	if false {
		derived: derivedNever: input.inputNever
	}

	_out1: [for svc, _ in derived {svc}]
	output: out1: yaml.Marshal(_out1)
}
-- out/compile --
--- in.cue
{
  issue3972: {
    output: {
      out0: "static"
    }
    input: {
      inputStatic: "static"
    }
    if false {
      input: {
        inputNever: "never"
      }
    }
    derived: {
      derivedStatic: "static"
    }
    if false {
      derived: {
        derivedNever: 〈2;input〉.inputNever
      }
    }
    _out1: [
      for svc, _ in 〈1;derived〉 {
        〈1;svc〉
      },
    ]
    output: {
      out1: 〈import;"encoding/yaml"〉.Marshal(〈1;_out1〉)
    }
  }
}
