# `cue export` incorrectly rejects a `#Size` definition with interdependent
# bound constraints (`num: >res | *(1+res)`, `max: >=num | *num`) when a
# concrete value is provided, e.g. `a: #Size & { num: 5 }`. Expected output
# would be `{ res: 0, num: 5, max: 5 }` but instead CUE reports empty
# disjunction errors for both `num` and `max`. Works correctly in v0.2.1.
# TODO: a bound value resolving to a disjunction should probably be an error.
# In this case #Size.amx should resolve.
# https://cuelang.org/issue/429
-- in.cue --
// Range disjunction without cycle (checks only one-way).
#Size: {
	res: uint | *0
	min: >res | *(1 + res)
	max: >min | *min
}

s0: #Size & {res: 1}

// This discards the default for max. This is correct, but unfortunate.
// TODO: is there a tweak to the default mechanism possible that would fix that?
//       Tread very carefully, though! Perhaps we could have a builtin that
//       discards any default, so that we can at least manually override this
//       behavior.
s1: #Size & {min: 5}
s2: #Size & {max: 5}
s3: #Size & {
	min: 5
	max: 10
}
es3: #Size & {
	min: 10
	max: 5
}

// Disjunctions with cycles
// TODO: improve error message here. Logic is correct, though.
#nonEmptyRange: {
	min: *1 | int
	min: <max
	max: >min
}
r1: #nonEmptyRange & {
	min: 3
}
r2: #nonEmptyRange & {
	max: 5
}
r3: #nonEmptyRange & {
	min: 3
	max: 6
}

er3: #nonEmptyRange & {
	min: 5
	max: 5
}
-- out/compile --
--- in.cue
{
  #Size: {
    res: (&(int, >=0)|*0)
    min: (>〈0;res〉|*(1 + 〈0;res〉))
    max: (>〈0;min〉|*〈0;min〉)
  }
  s0: (〈0;#Size〉 & {
    res: 1
  })
  s1: (〈0;#Size〉 & {
    min: 5
  })
  s2: (〈0;#Size〉 & {
    max: 5
  })
  s3: (〈0;#Size〉 & {
    min: 5
    max: 10
  })
  es3: (〈0;#Size〉 & {
    min: 10
    max: 5
  })
  #nonEmptyRange: {
    min: (*1|int)
    min: <〈0;max〉
    max: >〈0;min〉
  }
  r1: (〈0;#nonEmptyRange〉 & {
    min: 3
  })
  r2: (〈0;#nonEmptyRange〉 & {
    max: 5
  })
  r3: (〈0;#nonEmptyRange〉 & {
    min: 3
    max: 6
  })
  er3: (〈0;#nonEmptyRange〉 & {
    min: 5
    max: 5
  })
}
