-- in.cue --
// cmd/cue: misleading "field not allowed" error when a type clash occurs inside
// a disjunction; the actual conflict should be reported instead.
// https://cuelang.org/issue/570
issue570: {
	results: #DecodeOutput
	results: result: "hello"

	#Output: {
		result: _
	} | {
		error: string
	}

	#DecodeOutput: #Output & {
		result?: [... string]
		...
	}
}

// Clarify when an error resulted from a failed disjunction; error messages
// should indicate which disjunct failed rather than showing a generic error.
// https://cuelang.org/issue/516
issue516: {
	#Def: {
		match: metrics: string: {}
	} | {}

	x: #Def
	x: match: metrics: "foo": {}
}

// issue #465
explicitDefaultError: {
	a: string | *_|_

	if a != "" {}
}

// evaluator: export as YAML vs JSON emits different templated data when
// pattern constraints with defaults produce different disjunction results.
// https://cuelang.org/issue/2916
issue2916: {
	b: _
	[_]: c:      uint | *1
	[string]: c: >=3 | *3
}
// evaluator: inconsistent export output for different formats based on which
// default is selected when multiple defaults are unified.
// https://cuelang.org/issue/3157
issue3157: {
	foo: *42 | _
	foo: *43 | bool
}

// cmd/cue: every error in an empty disjunction should be reported, not just
// the first. Both disjuncts of `1 | 2` fail against the bound `>10`, and both
// "invalid value" errors are now reported even though they share the same
// primary position (the bound's location).
// https://cuelang.org/issue/4043
issue4043: {
	B: >10
	B: 1 | 2
}
-- issue3581.cue --
// evalv3: tools/flow unexpected error when a flow task result field is used as
// a list item; string interpolation in a list element caused a spurious error.
// https://cuelang.org/issue/3581
issue3581: reduced: {
	list: [...] | *[]
	list: ["\(c)"]
	c: _
}
-- issue3576.cue --
// evalv3: disjunct of definitions with identical optional fields results in
// incomplete evaluation; the resolved disjunct should be fully evaluated.
// https://cuelang.org/issue/3576
issue3576: reduced: {
	#A: a!: string
	#B: {
		if false {
			dummy: {}
		}
	}
	foo: #B | #A
	foo: a: "1"
}
issue3576: full: {
	#Run: {
		run!: string
		options?: #Option | [#Option, ...]
		if options != _|_ {
			optionsValue: options
		}
	}

	#Copy: {
		copy!: string
		options?: #Option | [#Option, ...]
		if options != _|_ {
			optionsValue: options
		}
	}

	#Option: {}

	foo: #Run | #Copy
	foo: run: "make"
}
-- issue3599.cue --
// evalv3: "explicit error in source" regression when using bottom (_|_) in
// repeating disjunctions; errors in optional/let fields should be ignored.
// https://cuelang.org/issue/3599
// Ignore errors for irrelevant fields like let and optional fields.
issue3599: full: {
	#Action: {
		action: {
			read!:  string
			write?: _|_
		} | {
			write!: string
			read?:  _|_
		}
	}

	#Minio: {
		container: #Action & {
			action: {
				read!:  string
				write?: _|_
			} | {
				write!: string
				read?:  _|_
			}
		}
		doWrite: bool | *true
		container: action: defaultAction
		defaultAction: {
			if doWrite {write: "somefile.txt"}
			if !doWrite {read: "somefile.txt"}
		}
	}
}
issue3599: reduced: p1: {
	{a?: 1 & 2} | {a: string, b?: 1 & 2}
	{} | {}
}
issue3599: reduced: p2: {
	{} | {}
	{a?: 1 & 2} | {a: string, b?: 1 & 2}
}
issue3599: let: {
	{} | {a: B | 1, let B = 1 & 2, }
	{} | {}
}
-- optionalerror.cue --
// evalv3 closedness regression with disjunctions and ellipses; a definition
// using _|_ in an optional field inside a disjunction caused spurious errors.
// https://cuelang.org/issue/4022
issue4022: reduced: {
	#NonNamespaced: metadata: namespace?: _|_
	#NullOrNonNamespaced: int | #NonNamespaced
	out:                  #NullOrNonNamespaced
	out:                  #NonNamespaced
	out: metadata: {}
}
issue4022: full: {
	#NonNamespaced: {
		metadata: {
			name!:      string
			namespace?: _|_
			...
		}
		...
	}

	#NullOrNonNamespaced: null | #NonNamespaced

	out: #NullOrNonNamespaced
	out: #NonNamespaced
	out: {
		metadata: name: "foo"
		apiVersion: "v1"
	}
}
-- out/compile --
--- in.cue
{
  issue570: {
    results: 〈0;#DecodeOutput〉
    results: {
      result: "hello"
    }
    #Output: ({
      result: _
    }|{
      error: string
    })
    #DecodeOutput: (〈0;#Output〉 & {
      result?: [
        ...string,
      ]
      ...
    })
  }
  issue516: {
    #Def: ({
      match: {
        metrics: {
          string: {}
        }
      }
    }|{})
    x: 〈0;#Def〉
    x: {
      match: {
        metrics: {
          foo: {}
        }
      }
    }
  }
  explicitDefaultError: {
    a: (string|*_|_(explicit error (_|_ literal) in source))
    if (〈0;a〉 != "") {}
  }
  issue2916: {
    b: _
    [_]: {
      c: (&(int, >=0)|*1)
    }
    [string]: {
      c: (>=3|*3)
    }
  }
  issue3157: {
    foo: (*42|_)
    foo: (*43|bool)
  }
  issue4043: {
    B: >10
    B: (1|2)
  }
}
--- issue3576.cue
{
  issue3576: {
    reduced: {
      #A: {
        a!: string
      }
      #B: {
        if false {
          dummy: {}
        }
      }
      foo: (〈0;#B〉|〈0;#A〉)
      foo: {
        a: "1"
      }
    }
  }
  issue3576: {
    full: {
      #Run: {
        run!: string
        options?: (〈1;#Option〉|[
          〈2;#Option〉,
          ...,
        ])
        if (〈0;options〉 != _|_(explicit error (_|_ literal) in source)) {
          optionsValue: 〈1;options〉
        }
      }
      #Copy: {
        copy!: string
        options?: (〈1;#Option〉|[
          〈2;#Option〉,
          ...,
        ])
        if (〈0;options〉 != _|_(explicit error (_|_ literal) in source)) {
          optionsValue: 〈1;options〉
        }
      }
      #Option: {}
      foo: (〈0;#Run〉|〈0;#Copy〉)
      foo: {
        run: "make"
      }
    }
  }
}
--- issue3581.cue
{
  issue3581: {
    reduced: {
      list: ([
        ...,
      ]|*[])
      list: [
        "\(〈1;c〉)",
      ]
      c: _
    }
  }
}
--- issue3599.cue
{
  issue3599: {
    full: {
      #Action: {
        action: ({
          read!: string
          write?: _|_(explicit error (_|_ literal) in source)
        }|{
          write!: string
          read?: _|_(explicit error (_|_ literal) in source)
        })
      }
      #Minio: {
        container: (〈1;#Action〉 & {
          action: ({
            read!: string
            write?: _|_(explicit error (_|_ literal) in source)
          }|{
            write!: string
            read?: _|_(explicit error (_|_ literal) in source)
          })
        })
        doWrite: (bool|*true)
        container: {
          action: 〈1;defaultAction〉
        }
        defaultAction: {
          if 〈1;doWrite〉 {
            write: "somefile.txt"
          }
          if !〈1;doWrite〉 {
            read: "somefile.txt"
          }
        }
      }
    }
  }
  issue3599: {
    reduced: {
      p1: {
        ({
          a?: (1 & 2)
        }|{
          a: string
          b?: (1 & 2)
        })
        ({}|{})
      }
    }
  }
  issue3599: {
    reduced: {
      p2: {
        ({}|{})
        ({
          a?: (1 & 2)
        }|{
          a: string
          b?: (1 & 2)
        })
      }
    }
  }
  issue3599: {
    let: {
      ({}|{
        a: (〈0;let B#1〉|1)
        let B#1 = (1 & 2)
      })
      ({}|{})
    }
  }
}
--- optionalerror.cue
{
  issue4022: {
    reduced: {
      #NonNamespaced: {
        metadata: {
          namespace?: _|_(explicit error (_|_ literal) in source)
        }
      }
      #NullOrNonNamespaced: (int|〈0;#NonNamespaced〉)
      out: 〈0;#NullOrNonNamespaced〉
      out: 〈0;#NonNamespaced〉
      out: {
        metadata: {}
      }
    }
  }
  issue4022: {
    full: {
      #NonNamespaced: {
        metadata: {
          name!: string
          namespace?: _|_(explicit error (_|_ literal) in source)
          ...
        }
        ...
      }
      #NullOrNonNamespaced: (null|〈0;#NonNamespaced〉)
      out: 〈0;#NullOrNonNamespaced〉
      out: 〈0;#NonNamespaced〉
      out: {
        metadata: {
          name: "foo"
        }
        apiVersion: "v1"
      }
    }
  }
}
