(module rc_own_param_drop
  (data IntList
    (doc "Recursive Int list — boxed.")
    (ctor Nil)
    (ctor Cons (con Int) (con IntList)))
  (fn head_or_zero
    (doc "Take ownership of an IntList; return its head if Cons, else 0. The tail is loaded as a pattern binder but never consumed — iter A dec's it at arm close. The outer cell is dec'd at fn return via iter B's Own-param emission.")
    (suppress (code "over-strict-mode") (because "RC codegen test: exercises Iter B Own-param dec at fn return"))
    (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) h))))
  (fn main
    (doc "Build a 5-element IntList; pass to head_or_zero (transferring ownership); print the result.")
    (type (fn-type (params) (ret (own (con Unit))) (effects IO)))
    (params)
    (body (let xs (term-ctor IntList Cons 11 (term-ctor IntList Cons 22 (term-ctor IntList Cons 33 (term-ctor IntList Cons 44 (term-ctor IntList Cons 55 (term-ctor IntList Nil)))))) (app print (app head_or_zero xs))))))
