#name: associativity of defaults
#evalFull
-- in.cue --
a: *"a" | ("b" | "c")
b: (*"a" | "b") | "c"
c: *"a" | (*"b" | "c")
x: a & b
y: b & c

s1: *1 | ((*2 | 3) & (2 | *3))
s2: *1 | ((*2 | 3) & (*2 | 3))
s3: *1 | ((*2 | 3) & 3)
s4: *1 | ((*2 | 3) & 2)
s5: *1 | *(*2 | 3)

e1: *(1 & 2) | (*"x" | string)
e2: (*"x" | string) | *(1 & 2)
-- complex.cue --
// add some test cases suggested by an automated prover based on this pattern:
// 1. ValK = (ValA & ValB_ND) & ValC_D \neq _|_ (the element we track must exist).
// 2. ValC_D & (ValA & ValB_D) = _|_ (for Path 1 Cond(ValC_D, Disj_AB) to be true).
// 3. ValC_D & ValB_D \neq _|_ (for Path 2 Cond(ValC_D, Disj_B) to be false).

// Let's define these CUE values. The trick is that ValA must introduce a
// component that causes ValC_D to conflict with (ValA & ValB_D),
// but ValC_D must *not* conflict with ValB_D on its own.
t1: {
	va: {a: 1, b: 2}
	vb1: {c: 3}
	vb2: {c: 4}
	vc: {c: 4}
	vd: string

	A: va | vd
	B: *vb1 | vb2 | vd
	C: *vc | vd

	p1: (A & B) & C
	p2: A & (B & C)
}
t2: {
	va:  0 | 1 | 2
	vb1: 2 | 3
	vb2: 0 | 1 | 4
	vc:  0 | 3 | 4
	vd:  string

	A: va | vd
	B: *vb1 | vb2 | vd
	C: *vc | vd

	p1: (A & B) & C
	p2: A & (B & C)
}
-- issue3908.cue --
// issue3908: Tests that nested defaults (e.g. null default overridden by a
// string default) are handled correctly in evalv3. https://cuelang.org/issue/3908
issue3908: reduced: {
	string | *null
	string | *"str"
}
issue3908: full: {
	out: #Schema & {field: string | *"dataDefault"}
	#Schema: field: string | *null
}
-- out/compile --
--- complex.cue
{
  t1: {
    va: {
      a: 1
      b: 2
    }
    vb1: {
      c: 3
    }
    vb2: {
      c: 4
    }
    vc: {
      c: 4
    }
    vd: string
    A: (〈0;va〉|〈0;vd〉)
    B: (*〈0;vb1〉|〈0;vb2〉|〈0;vd〉)
    C: (*〈0;vc〉|〈0;vd〉)
    p1: ((〈0;A〉 & 〈0;B〉) & 〈0;C〉)
    p2: (〈0;A〉 & (〈0;B〉 & 〈0;C〉))
  }
  t2: {
    va: (0|1|2)
    vb1: (2|3)
    vb2: (0|1|4)
    vc: (0|3|4)
    vd: string
    A: (〈0;va〉|〈0;vd〉)
    B: (*〈0;vb1〉|〈0;vb2〉|〈0;vd〉)
    C: (*〈0;vc〉|〈0;vd〉)
    p1: ((〈0;A〉 & 〈0;B〉) & 〈0;C〉)
    p2: (〈0;A〉 & (〈0;B〉 & 〈0;C〉))
  }
}
--- in.cue
{
  a: (*"a"|("b"|"c"))
  b: ((*"a"|"b")|"c")
  c: (*"a"|(*"b"|"c"))
  x: (〈0;a〉 & 〈0;b〉)
  y: (〈0;b〉 & 〈0;c〉)
  s1: (*1|((*2|3) & (2|*3)))
  s2: (*1|((*2|3) & (*2|3)))
  s3: (*1|((*2|3) & 3))
  s4: (*1|((*2|3) & 2))
  s5: (*1|*(*2|3))
  e1: (*(1 & 2)|(*"x"|string))
  e2: ((*"x"|string)|*(1 & 2))
}
--- issue3908.cue
{
  issue3908: {
    reduced: {
      (string|*null)
      (string|*"str")
    }
  }
  issue3908: {
    full: {
      out: (〈0;#Schema〉 & {
        field: (string|*"dataDefault")
      })
      #Schema: {
        field: (string|*null)
      }
    }
  }
}
