-- in.cue --
a: b - 100
b: a + 100

c: [c[1], c[0]]

d: e - 1
e: 1 + d
e: *2 | 0
-- disjunction.cue --
oneway: {
	t1: {
		a: *1 | int
		a: b + 1
		b: <a
	}
	t2: t1 & {
		a: 3
	}
}
// This should report a cycle error. TODO: this should also resolve.
issue3669: {
	#Schema: {
		two: 1 + one
		one: two - 1
	}

	out: #Schema & {
		two: 0 | *2
	}
}
-- issue3737.cue --
// Apparent cycle issue in evalv3 when combining a definition with a default
// disjunction and a derived field value.
// https://cuelang.org/issue/3737
issue3737: reduced1: {
	#A: {
		a: b * 12
		b: a / 12
	}

	x: #A
	x: b: 1000.0

	y: #A | *x
	y: b: x.b * 0.7
}
issue3737: reduced2: {
	x: #TimeSpan & {
		start: y.start
		end:   1000.0
	}
	y: #TimeSpan & {
		duration: 100.0
		end:      x.end
	}
	#TimeSpan: {
		start:    end - duration
		duration: end - start
		end:      start + duration
	}
}
-- out/compile --
--- disjunction.cue
{
  oneway: {
    t1: {
      a: (*1|int)
      a: (〈0;b〉 + 1)
      b: <〈0;a〉
    }
    t2: (〈0;t1〉 & {
      a: 3
    })
  }
  issue3669: {
    #Schema: {
      two: (1 + 〈0;one〉)
      one: (〈0;two〉 - 1)
    }
    out: (〈0;#Schema〉 & {
      two: (0|*2)
    })
  }
}
--- in.cue
{
  a: (〈0;b〉 - 100)
  b: (〈0;a〉 + 100)
  c: [
    〈1;c〉[1],
    〈1;c〉[0],
  ]
  d: (〈0;e〉 - 1)
  e: (1 + 〈0;d〉)
  e: (*2|0)
}
--- issue3737.cue
{
  issue3737: {
    reduced1: {
      #A: {
        a: (〈0;b〉 * 12)
        b: (〈0;a〉 / 12)
      }
      x: 〈0;#A〉
      x: {
        b: 1000.0
      }
      y: (〈0;#A〉|*〈0;x〉)
      y: {
        b: (〈1;x〉.b * 0.7)
      }
    }
  }
  issue3737: {
    reduced2: {
      x: (〈0;#TimeSpan〉 & {
        start: 〈1;y〉.start
        end: 1000.0
      })
      y: (〈0;#TimeSpan〉 & {
        duration: 100.0
        end: 〈1;x〉.end
      })
      #TimeSpan: {
        start: (〈0;end〉 - 〈0;duration〉)
        duration: (〈0;end〉 - 〈0;start〉)
        end: (〈0;start〉 + 〈0;duration〉)
      }
    }
  }
}
