#inlinetest:exclude CUE source contains compile-time errors (try-clause syntax, missing
# references) which prevent the inline runner from compiling the source.
-- in.cue --
@experiment(try)

// Struct-form try must be the last clause
structFormNotLast: {
    try if true { x: 1 }
}

// ? marker outside try context
optionalOutsideTry: {
    a: 1
    b: a?
}

// ? marker in for clause source (outside try)
optionalInForSource: {
    a?: [1, 2, 3]
    for x in a? { "\(x)": x }
}

// ? marker in body of assignment-form try
optionalInAssignmentBody: {
    a: 1
    b: 2
    try y = a? { x: b? } else { fallback: 23 }
}

// Struct-form try must be the last clause
invalidUseOfOptional: {
    try { x: c? }
}

-- out/compile --
structFormNotLast: struct-form try clause must be the last clause in a comprehension:
    ./in.cue:5:5
optionalOutsideTry.b: optional marker (?) is only valid within a try clause:
    ./in.cue:11:8
optionalInForSource: optional marker (?) is only valid within a try clause:
    ./in.cue:17:14
optionalInAssignmentBody.try[].x: optional marker (?) is only valid within a try clause:
    ./in.cue:24:21
invalidUseOfOptional.x: reference "c" not found:
    ./in.cue:29:14
--- in.cue
{
  structFormNotLast: {
    _|_(struct-form try clause must be the last clause in a comprehension)
  }
  optionalOutsideTry: {
    a: 1
    b: 〈0;a〉?
  }
  optionalInForSource: {
    a?: [
      1,
      2,
      3,
    ]
    for _, x in 〈0;a〉? {
      "\(〈1;x〉)": 〈1;x〉
    }
  }
  optionalInAssignmentBody: {
    a: 1
    b: 2
    try y = 〈0;a〉? {
      x: 〈2;b〉?
    } else {
      fallback: 23
    }
  }
  invalidUseOfOptional: {
    try {
      x: _|_(reference "c" not found)
    }
  }
}
