@@ -211,7 +211,7 @@ genAll i args
211 let p = resugar (PApp fc (PRef fc n) (zipWith upd xs' xs))
211 let p = resugar (PApp fc (PRef fc n) (zipWith upd xs' xs))
212 let tyn = getTy n (tt_ctxt i)
212 let tyn = getTy n (tt_ctxt i)
213 case lookupCtxt tyn (idris_datatypes i) of
213 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])
216 ops fc n arg o = return Placeholder
216 ops fc n arg o = return Placeholder
@@ -265,29 +265,38 @@ checkAllCovering fc done top n | not (n `elem` done)
265 x -> return () -- stop if total
265 x -> return () -- stop if total
266checkAllCovering _ _ _ _ = return ()
266checkAllCovering _ _ _ _ = return ()
268+-- Check if, in a given group of type declarations mut_ns,
268−-- Check if, in a given type n, the constructor cn : ty is strictly positive,
269+-- the constructor cn : ty is strictly positive,
269-- and update the context accordingly
270-- and update the context accordingly
271−checkPositive :: Name -> (Name, Type) -> Idris ()
272+checkPositive :: [Name] -> (Name, Type) -> Idris Totality
272−checkPositive n (cn, ty')
273+checkPositive mut_ns (cn, ty')
273− = do let ty = delazy ty'
274+ = do let ty = delazy' True ty'
274 let p = cp ty
275 let p = cp ty
275 i <- getIState
276 i <- getIState
276 let tot = if p then Total (args ty) else Partial NotPositive
277 let tot = if p then Total (args ty) else Partial NotPositive
277 let ctxt' = setTotal cn tot (tt_ctxt i)
278 let ctxt' = setTotal cn tot (tt_ctxt i)
278 putIState (i { tt_ctxt = ctxt' })
279 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
280 addIBC (IBCTotal cn tot)
281 addIBC (IBCTotal cn tot)
282 args t = [0..length (getArgTys t)-1]
284 args t = [0..length (getArgTys t)-1]
284 cp (Bind n (Pi aty) sc) = posArg aty && cp sc
286 cp (Bind n (Pi aty) sc) = posArg aty && cp sc
287+ cp t | (P _ n' _, args) <- unApply t,
288+ n' `elem` mut_ns = all noRec args
285− cp t = True
289+ cp _ = True
287 posArg (Bind _ (Pi nty) sc)
291 posArg (Bind _ (Pi nty) sc)
288 | (P _ n' _, args) <- unApply nty
292 | (P _ n' _, args) <- unApply nty
289− = n /= n' && posArg sc
293+ = n' `notElem` mut_ns && all noRec args && posArg sc
290− posArg t = True
294+ posArg t | (P _ n' _, args) <- unApply t,
295+ n' `elem` mut_ns = all noRec args
298+ noRec arg = all (\x -> x `notElem` mut_ns) (allTTNames arg)
292calcProd :: IState -> FC -> Name -> [([Name], Term, Term)] -> Idris Totality
301calcProd :: IState -> FC -> Name -> [([Name], Term, Term)] -> Idris Totality
293calcProd i fc topn pats
302calcProd i fc topn pats
@@ -335,7 +344,7 @@ calcProd i fc topn pats
335 cotype (DCon _ _) n ty
344 cotype (DCon _ _) n ty
336 | (P _ t _, _) <- unApply (getRetTy ty)
345 | (P _ t _, _) <- unApply (getRetTy ty)
337 = case lookupCtxt t (idris_datatypes i) of
346 = case lookupCtxt t (idris_datatypes i) of
338− [TI _ True _ _] -> True
347+ [TI _ True _ _ _] -> True
339 _ -> False
348 _ -> False
340 cotype nt n ty = False
349 cotype nt n ty = False
@@ -383,6 +392,14 @@ checkTotality path fc n
383 setTotality n t'
392 setTotality n t'
384 addIBC (IBCTotal n t')
393 addIBC (IBCTotal n t')
385 return t'
394 return t'
395+ [TyDecl (DCon _ _) ty] ->
396+ case unApply (getRetTy ty) of
397+ (P _ tyn _, _) -> do
398+ let ms = case lookupCtxt tyn (idris_datatypes i) of
399+ [TI _ _ _ _ xs@(_:_)] -> xs
401+ checkPositive ms (n, ty)
402+ _-> return $ Total []
386 _ -> return $ Total []
403 _ -> return $ Total []
387 x -> return x
404 x -> return x
388 case t' of
405 case t' of
@@ -556,7 +573,7 @@ buildSCG' ist pats args = nub $ concatMap scgPat pats where
557 isInductive (P _ nty _) (P _ nty' _) =
574 isInductive (P _ nty _) (P _ nty' _) =
558 let co = case lookupCtxt nty (idris_datatypes ist) of
575 let co = case lookupCtxt nty (idris_datatypes ist) of
559− [TI _ x _ _] -> x
576+ [TI _ x _ _ _] -> x
560 _ -> False in
577 _ -> False in
561 nty == nty' && not co
578 nty == nty' && not co
562 isInductive _ _ = False
579 isInductive _ _ = False
@@ -639,7 +656,7 @@ checkMP ist i mp = if i > 0
639 = case lookupTotal f (tt_ctxt ist) of
656 = case lookupTotal f (tt_ctxt ist) of
640 [Total _] -> Unchecked -- okay so far
657 [Total _] -> Unchecked -- okay so far
641 [Partial _] -> Partial (Other [f])
658 [Partial _] -> Partial (Other [f])
642− x -> error (show x)
659+ x -> error $ "CAN'T HAPPEN: " ++ (show x)
643 | [TyDecl (TCon _ _) _] <- lookupDef f (tt_ctxt ist)
660 | [TyDecl (TCon _ _) _] <- lookupDef f (tt_ctxt ist)
644 = Total []
661 = Total []
645 tryPath desc path (e@(f, args) : es) arg
662 tryPath desc path (e@(f, args) : es) arg