@@ -211,7 +211,7 @@ genAll i args
211211 let p = resugar (PApp fc (PRef fc n) (zipWith upd xs' xs))
212212 let tyn = getTy n (tt_ctxt i)
213213 case lookupCtxt tyn (idris_datatypes i) of
214− (TI ns _ _ _ : _) -> p : map (mkPat fc) (ns \\ [n])
214+ (TI ns _ _ _ _ : _) -> p : map (mkPat fc) (ns \\ [n])
215215 _ -> [p]
216216 ops fc n arg o = return Placeholder
217217
@@ -265,19 +265,21 @@ checkAllCovering fc done top n | not (n `elem` done)
265265 x -> return () -- stop if total
266266checkAllCovering _ _ _ _ = return ()
267267
268−-- Check if, in a given type n, the constructor cn : ty is strictly positive,
268+-- Check if, in a given group of type declarations mut_ns,
269+-- the constructor cn : ty is strictly positive,
269270-- and update the context accordingly
270271
271−checkPositive :: Name -> (Name, Type) -> Idris ()
272−checkPositive n (cn, ty')
272+checkPositive :: [Name] -> (Name, Type) -> Idris Totality
273+checkPositive mut_ns (cn, ty')
273274 = do let ty = delazy ty'
274275 let p = cp ty
275276 i <- getIState
276277 let tot = if p then Total (args ty) else Partial NotPositive
277278 let ctxt' = setTotal cn tot (tt_ctxt i)
278279 putIState (i { tt_ctxt = ctxt' })
279− logLvl 5 $ "Constructor " ++ show cn ++ " is " ++ show tot
280+ logLvl 5 $ "Constructor " ++ show cn ++ " is " ++ show tot ++ " with " ++ show mut_ns
280281 addIBC (IBCTotal cn tot)
282+ return tot
281283 where
282284 args t = [0..length (getArgTys t)-1]
283285
@@ -286,7 +288,7 @@ checkPositive n (cn, ty')
286288
287289 posArg (Bind _ (Pi nty) sc)
288290 | (P _ n' _, args) <- unApply nty
289− = n /= n' && posArg sc
291+ = n' `notElem` mut_ns && posArg sc
290292 posArg t = True
291293
292294calcProd :: IState -> FC -> Name -> [([Name], Term, Term)] -> Idris Totality
@@ -335,7 +337,7 @@ calcProd i fc topn pats
335337 cotype (DCon _ _) n ty
336338 | (P _ t _, _) <- unApply (getRetTy ty)
337339 = case lookupCtxt t (idris_datatypes i) of
338− [TI _ True _ _] -> True
340+ [TI _ True _ _ _] -> True
339341 _ -> False
340342 cotype nt n ty = False
341343
@@ -383,6 +385,14 @@ checkTotality path fc n
383385 setTotality n t'
384386 addIBC (IBCTotal n t')
385387 return t'
388+ [TyDecl (DCon _ _) ty] ->
389+ case unApply (getRetTy ty) of
390+ (P _ tyn _, _) -> do
391+ let ms = case lookupCtxt tyn (idris_datatypes i) of
392+ [TI _ _ _ _ xs@(_:_)] -> xs
393+ ts -> [tyn]
394+ checkPositive ms (n, ty)
395+ _-> return $ Total []
386396 _ -> return $ Total []
387397 x -> return x
388398 case t' of
@@ -556,7 +566,7 @@ buildSCG' ist pats args = nub $ concatMap scgPat pats where
556566
557567 isInductive (P _ nty _) (P _ nty' _) =
558568 let co = case lookupCtxt nty (idris_datatypes ist) of
559− [TI _ x _ _] -> x
569+ [TI _ x _ _ _] -> x
560570 _ -> False in
561571 nty == nty' && not co
562572 isInductive _ _ = False
@@ -639,7 +649,7 @@ checkMP ist i mp = if i > 0
639649 = case lookupTotal f (tt_ctxt ist) of
640650 [Total _] -> Unchecked -- okay so far
641651 [Partial _] -> Partial (Other [f])
642− x -> error (show x)
652+ x -> error $ "CAN'T HAPPEN: " ++ (show x)
643653 | [TyDecl (TCon _ _) _] <- lookupDef f (tt_ctxt ist)
644654 = Total []
645655 tryPath desc path (e@(f, args) : es) arg