; Fieldtest kem.2 (Axis 2, (new T args) term construct) — derived
; from the spec's prep.2 § "Iteration prep.2 — `new` term construct"
; worked example, kept literally identical to that example so the
; outcome speaks to the spec's own promise.
;
; Outcome:
;   - `ail check` clean (the construct elaborates).
;   - `ail run` fails with the codegen-deferral error
;     "Term::New cannot be synthed at codegen — must be desugared
;     first; codegen support lands in the raw-buf milestone".
;     Per spec § Architecture this is the explicit out-of-scope of
;     the milestone; recorded as a `working` finding (the diagnostic
;     correctly names the future milestone and is precise enough that
;     an LLM author can route to the right next step).

(module kem_2_counter_new

  (data Counter
    (ctor MkCounter (con Int)))

  (fn new
    (doc "Build a Counter initialised to the given value.")
    (type (fn-type (params (own (con Int))) (ret (own (con Counter)))))
    (params n)
    (body (term-ctor Counter MkCounter n)))

  (fn main
    (type (fn-type (params) (ret (own (con Unit))) (effects IO)))
    (params)
    (body
      (let c (new Counter 42)
        (match c
          (case (pat-ctor MkCounter x)
            (seq (app print x) (do io/print_str "\n"))))))))
