@@ -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,19 +265,21 @@ 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 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]
@@ -286,7 +288,7 @@ checkPositive n (cn, ty')
287 posArg (Bind _ (Pi nty) sc)
289 posArg (Bind _ (Pi nty) sc)
288 | (P _ n' _, args) <- unApply nty
290 | (P _ n' _, args) <- unApply nty
289− = n /= n' && posArg sc
291+ = n' `notElem` mut_ns && posArg sc
290 posArg t = True
292 posArg t = True
292calcProd :: IState -> FC -> Name -> [([Name], Term, Term)] -> Idris Totality
294calcProd :: IState -> FC -> Name -> [([Name], Term, Term)] -> Idris Totality
@@ -335,7 +337,7 @@ calcProd i fc topn pats
335 cotype (DCon _ _) n ty
337 cotype (DCon _ _) n ty
336 | (P _ t _, _) <- unApply (getRetTy ty)
338 | (P _ t _, _) <- unApply (getRetTy ty)
337 = case lookupCtxt t (idris_datatypes i) of
339 = case lookupCtxt t (idris_datatypes i) of
338− [TI _ True _ _] -> True
340+ [TI _ True _ _ _] -> True
339 _ -> False
341 _ -> False
340 cotype nt n ty = False
342 cotype nt n ty = False
@@ -383,6 +385,14 @@ checkTotality path fc n
383 setTotality n t'
385 setTotality n t'
384 addIBC (IBCTotal n t')
386 addIBC (IBCTotal n t')
385 return t'
387 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
394+ checkPositive ms (n, ty)
395+ _-> return $ Total []
386 _ -> return $ Total []
396 _ -> return $ Total []
387 x -> return x
397 x -> return x
388 case t' of
398 case t' of
@@ -556,7 +566,7 @@ buildSCG' ist pats args = nub $ concatMap scgPat pats where
557 isInductive (P _ nty _) (P _ nty' _) =
567 isInductive (P _ nty _) (P _ nty' _) =
558 let co = case lookupCtxt nty (idris_datatypes ist) of
568 let co = case lookupCtxt nty (idris_datatypes ist) of
559− [TI _ x _ _] -> x
569+ [TI _ x _ _ _] -> x
560 _ -> False in
570 _ -> False in
561 nty == nty' && not co
571 nty == nty' && not co
562 isInductive _ _ = False
572 isInductive _ _ = False
@@ -639,7 +649,7 @@ checkMP ist i mp = if i > 0
639 = case lookupTotal f (tt_ctxt ist) of
649 = case lookupTotal f (tt_ctxt ist) of
640 [Total _] -> Unchecked -- okay so far
650 [Total _] -> Unchecked -- okay so far
641 [Partial _] -> Partial (Other [f])
651 [Partial _] -> Partial (Other [f])
642− x -> error (show x)
652+ x -> error $ "CAN'T HAPPEN: " ++ (show x)
643 | [TyDecl (TCon _ _) _] <- lookupDef f (tt_ctxt ist)
653 | [TyDecl (TCon _ _) _] <- lookupDef f (tt_ctxt ist)
644 = Total []
654 = Total []
645 tryPath desc path (e@(f, args) : es) arg
655 tryPath desc path (e@(f, args) : es) arg