; Positive-coverage fixture (spec 0062): a let-binder whose value
; is the result of an `(own T)`-ret-mode fn call IS trackable for
; scope-close drop. The callee's `(own T)` return signs the static
; contract that the caller now owns the returned cell, so the
; let-scope close emits the caller dec and the cell frees cleanly.
;
; Pre-0062 this fn's return was the legacy `Implicit` lane, which
; codegen treated as "do not dec — leak rather than mis-dec",
; giving `live = 1`. Deleting `Implicit` (binary {Own, Borrow})
; makes the return `Own`, the dec fires, and the cell frees —
; this is the typed-MIR leak fix the cutover delivers.
;
; Properties guarded:
; (1) Build succeeds (no consume-while-borrowed false positive).
; (2) Binary exits cleanly with stdout `7` (no crash, no
;     refcount underflow).
; (3) `live = 0` at program exit — the one MkT cell frees. The
;     own-return contract flows ownership to the caller, which
;     dec's it at scope close.

(module rc_let_implicit_returning_app

  (data T
    (ctor MkT (con Int)))

  ; No ret-mode annotation -> default Implicit. Takes one
  ; ignored Int param (form-A doesn't allow zero-arg fn-app).
  (fn alloc
    (type
      (fn-type
        (params (own (con Int)))
        (ret (own (con T)))))
    (params n)
    (body
      (term-ctor T MkT n)))

  (fn unbox
    (type
      (fn-type
        (params (borrow (con T)))
        (ret (own (con Int)))))
    (params x)
    (body
      (match x
        (case (pat-ctor MkT v) v))))

  (fn main
    (type (fn-type (params) (ret (own (con Unit))) (effects IO)))
    (params)
    (body
      (let x (app alloc 7)
        (app print (app unbox x)))))
)
