@@ -342,7 +342,7 @@ checkPositive :: [Name] -- ^ the group of type declarations
342342checkPositive mut_ns (cn, ty')
343343 = do i <- getIState
344344 let ty = delazy' True (normalise (tt_ctxt i) [] ty')
345− let p = cp ty
345+ let p = cp i ty
346346 let tot = if p then Total (args ty) else Partial NotPositive
347347 let ctxt' = setTotal cn tot (tt_ctxt i)
348348 putIState (i { tt_ctxt = ctxt' })
@@ -352,20 +352,29 @@ checkPositive mut_ns (cn, ty')
352352 where
353353 args t = [0..length (getArgTys t)-1]
354354
355− cp (Bind n (Pi _ aty _) sc) = posArg aty && cp sc
356− cp t | (P _ n' _, args) <- unApply t,
357− n' `elem` mut_ns = all noRec args
358− cp _ = True
355+ cp i (Bind n (Pi _ aty _) sc)
356+ = posArg i aty && cp i sc
357+ cp i t | (P _ n' _ , args) <- unApply t,
358+ n' `elem` mut_ns = all noRec args
359+ cp i _ = True
359360
360− posArg (Bind _ (Pi _ nty _) sc)
361− | (P _ n' _, args) <- unApply nty
362− = n' `notElem` mut_ns && all noRec args && posArg sc
363− posArg t | (P _ n' _, args) <- unApply t,
364− n' `elem` mut_ns = all noRec args
365− posArg _ = True
361+ posArg ist (Bind _ (Pi _ nty _) sc) = noRec nty && posArg ist sc
362+ posArg ist t = posParams ist t
366363
367364 noRec arg = all (\x -> x `notElem` mut_ns) (allTTNames arg)
368365
366+ -- If the type appears recursively in a parameter argument, that's
367+ -- fine, otherwise if it appears in an argument it's not fine.
368+ posParams ist t | (P _ n _, args) <- unApply t
369+ = case lookupCtxtExact n (idris_datatypes ist) of
370+ Just ti -> checkParamsOK (param_pos ti) 0 args
371+ Nothing -> and (map (posParams ist) args)
372+ posParams ist t = noRec t
373+
374+ checkParamsOK ppos i [] = True
375+ checkParamsOK ppos i (p : ps)
376+ | i `elem` ppos = checkParamsOK ppos (i + 1) ps
377+ | otherwise = noRec p && checkParamsOK ppos (i + 1) ps
369378
370379-- | Calculate the totality of a function from its patterns. Either
371380-- follow the size change graph (if inductive) or check for