::: {A:i8, B:i8?, R:{A:r8, X:i8, Y:i2, S:{X:i8}}, T:{A:r8, X:i8, Y:i2, S:{X:i8}}?*}

// Each matching group is started with a "// Match" comment on the first line, so it shows in the baselines.

With(3, 5) // Match
With(v : 3, 5)

With(v : 3,  v + 5) // Match
With(    3, it + 5)

With(v : 3, w :  v + 5,    v *    w) // Match
With(    3,     it + 5, it$1 * it$0)

With(v : A + B,  v *  v) // Match
With(    A + B, it * it)

With(    R,    X *    Y) // Match
With(r : R,  r.X *  r.Y)
With(    R, it.X * it.Y)

With(    R.S,    X *    X) // Match
With(s : R.S,  s.X *  s.X)
With(    R.S, it.X * it.X)

With(    Wrap(R),       S, it$1.X *      X) // Match
With(    Wrap(R),       S, it$1.X * it$0.X)
With(    Wrap(R),    it.S, it$1.X *      X)
With(    Wrap(R),    it.S, it$1.X * it$0.X)
With(r : Wrap(R),     r.S,    r.X *      X)
With(r : Wrap(R),     r.S,    r.X * it$0.X)
With(r : Wrap(R), s : r.S,    r.X *    s.X)

With(    R,       S, it$1.X *      X) // Match
With(    R,       S, it$1.X * it$0.X)
With(    R,    it.S, it$1.X *      X)
With(    R,    it.S, it$1.X * it$0.X)
With(r : R,     r.S,    r.X *      X)
With(r : R,     r.S,    r.X * it$0.X)
With(r : R, s : r.S,    r.X *    s.X)

With(Wrap(R), it)
With(Wrap(R), @A, it)
With(Wrap(R), @A, it$1.A)
With(Wrap(R), @A, A)
With(Wrap(R), @A, A + it$1.A + it$0)

// Errors:
With(Wrap(R), it$1)
With(Wrap(R), @A, A + it$1.A + it$1)
With(Wrap(R), @A, A + it$1.A + it$2)

With(Wrap(R), -it)
With(Wrap(R), not it)
With(Wrap(R), it%)

With(Wrap(R), it+it)
With(Wrap(R), it*it)
With(Wrap(R), it/it)
With(Wrap(R), it and it)
With(Wrap(R), it or it)
With(Wrap(R), it & it)
With(Wrap(R), it in it)
With(Wrap(R), it has it)
With(Wrap(R), it ?? it)

With(1, it = "s")

With(a:Wrap(R), b:Wrap(R), c: b.Y + 17, a.A * a.X + b.A * b.X + c * c)

// 1st substitutes and removes s.
// 2nd propogates constants, determing that x = 3, y = 0, z = 0, and removes x, y, and z.
// 3rd removes a since it is no longer used (z is zero).
With(s: Range(3), a: A * A, x: s->Count(), y: x + x - 6, z: y * a * a * y, z * z)

// Found by fuzz testing. Tests inserted Withs' reductions.
{a:"a"} ?? ({b:false} ?? null->{c:"c"})
(([[2]] - 1 > 3) and false) and ("a" > ["b"])
(([[{b:2}]] - 1) and false) and ("a" > [{c:1}]) // Error.
::: {S1: i8*, S2:i8**}
(S2 > 3 and false) and (S1 > 0)

::: {A:{M:b, N:i8}*}
// Tests out of bounds indexing on inserted With reduction. The iarg
// indexed into the wrong ArgTraits object.
ForEach(A, IfElse(M, M, M-[N]))