(module flat_pat_shadow_control
  (data IntList
    (ctor Nil)
    (ctor Cons (con Int) (con IntList)))
  (data Box (vars a)
    (ctor MkBox a))
  (fn blen
    (doc "borrow-only length over a borrowed IntList")
    (type (fn-type (params (borrow (con IntList))) (ret (own (con Int)))))
    (params xs)
    (body (match xs
      (case (pat-ctor Nil) 0)
      (case (pat-ctor Cons h t) (app + 1 (app blen t))))))
  (fn csum
    (doc "consuming sum over an IntList")
    (type (fn-type (params (own (con IntList))) (ret (own (con Int)))))
    (params xs)
    (body (match xs
      (case (pat-ctor Nil) 0)
      (case (pat-ctor Cons h t) (app + h (app csum t))))))
  (fn main
    (doc "Alpha-renamed control for flat_pat_shadow_leak.ail (refs #43): structurally identical, but the inner flat-match pattern-binder is `y` (no shadow of the outer `x`). The inner payload's arm-close drop fires because (def,\"y\") does not collide with (def,\"x\"). This is the live-count baseline the shadow fixture must reach once binder names are unique per fn at desugar (C').")
    (type (fn-type (params) (ret (own (con Unit))) (effects IO)))
    (params)
    (body
      (let x (term-ctor IntList Cons 1 (term-ctor IntList Nil))
        (seq
          (match (term-ctor Box MkBox (term-ctor IntList Cons 2 (term-ctor IntList Nil)))
            (case (pat-ctor MkBox y)
              (app print (app blen y))))
          (app print (app csum x)))))))
