# Tests incomplete-error reporting for various expressions: string arithmetic,
# non-concrete bounds, self-referential bounds, mutual dependencies, and
# undefined-field lookups. All produce [incomplete] errors except e2 which
# succeeds because "bar" is concrete. issue1837 checks that incomplete errors
# are correctly preferred over cycle errors in conditional comprehensions.
-- in.cue --
s: string

e1:  s + s
e2:  >"bar" & s // okay: "bar" is concrete, result is a valid bound
e3:  >s & "foo"
e3b: >s

e4: >e1 & s
e5: <e5 & s

E: {
	a: c - b
	b: c - a
	c: a+b & >=5
}

a:    int
okay: (>10 & <a) + 3

// No output or "cycle error" when checking existence of non-existing fields;
// an incomplete error should be reported instead of a cycle error.
// https://cuelang.org/issue/1837
issue1837: {
	// x is properly recognized as erroneous and the "message" field is added
	// with the value "a", instead of as a cycle error.

	// TODO(inline): use permute, but ensure comprehensions are permuted too first.
	// @test(permute)
	p1: {
		context: {}
		x: context.b
		if x == _|_ {
			message: "a"
		}
	}
	p2: {
		if x == _|_ {
			message: "a"
		}
		x: context.b
		context: {}
	}
	p3: {
		if x == _|_ {
			message: "a"
		}
		context: {}
		x: context.b
	}
}
-- out/compile --
--- in.cue
{
  s: string
  e1: (〈0;s〉 + 〈0;s〉)
  e2: (>"bar" & 〈0;s〉)
  e3: (>〈0;s〉 & "foo")
  e3b: >〈0;s〉
  e4: (>〈0;e1〉 & 〈0;s〉)
  e5: (<〈0;e5〉 & 〈0;s〉)
  E: {
    a: (〈0;c〉 - 〈0;b〉)
    b: (〈0;c〉 - 〈0;a〉)
    c: ((〈0;a〉 + 〈0;b〉) & >=5)
  }
  a: int
  okay: ((>10 & <〈0;a〉) + 3)
  issue1837: {
    p1: {
      context: {}
      x: 〈0;context〉.b
      if (〈0;x〉 == _|_(explicit error (_|_ literal) in source)) {
        message: "a"
      }
    }
    p2: {
      if (〈0;x〉 == _|_(explicit error (_|_ literal) in source)) {
        message: "a"
      }
      x: 〈0;context〉.b
      context: {}
    }
    p3: {
      if (〈0;x〉 == _|_(explicit error (_|_ literal) in source)) {
        message: "a"
      }
      context: {}
      x: 〈0;context〉.b
    }
  }
}
