@@ -630,12 +630,12 @@ checkMP ist i mp = if i > 0
630 = let res = tryPath d path mp arg in
630 = let res = tryPath d path mp arg in
631 trace (show mp ++ "\n" ++ show arg ++ " " ++ show res) res
631 trace (show mp ++ "\n" ++ show arg ++ " " ++ show res) res
633− tryPath :: Int -> [(SCGEntry, Int)] -> MultiPath -> Int -> Totality
633+ tryPath :: Int -> [((SCGEntry, Int), Int)] -> MultiPath -> Int -> Totality
634 tryPath desc path [] _ = Total []
634 tryPath desc path [] _ = Total []
635-- tryPath desc path ((UN "believe_me", _) : _) arg
635-- tryPath desc path ((UN "believe_me", _) : _) arg
636-- = Partial BelieveMe
636-- = Partial BelieveMe
637 -- if we get to a constructor, it's fine as long as it's strictly positive
637 -- if we get to a constructor, it's fine as long as it's strictly positive
638− tryPath desc path ((f, _) :es) arg
638+ tryPath desc path ((f, _) : es) arg
639 | [TyDecl (DCon _ _) _] <- lookupDef f (tt_ctxt ist)
639 | [TyDecl (DCon _ _) _] <- lookupDef f (tt_ctxt ist)
640 = case lookupTotal f (tt_ctxt ist) of
640 = case lookupTotal f (tt_ctxt ist) of
641 [Total _] -> Unchecked -- okay so far
641 [Total _] -> Unchecked -- okay so far
@@ -646,12 +646,15 @@ checkMP ist i mp = if i > 0
646 tryPath desc path (e@(f, args) : es) arg
646 tryPath desc path (e@(f, args) : es) arg
647 | e `elem` es && allNothing args = Partial (Mutual [f])
647 | e `elem` es && allNothing args = Partial (Mutual [f])
648 tryPath desc path (e@(f, nextargs) : es) arg
648 tryPath desc path (e@(f, nextargs) : es) arg
649− | Just d <- lookup e path
649+ | Just d <- lookup (e, arg) path
650 = if desc > 0
650 = if desc > 0
651 then -- trace ("Descent " ++ show (desc - d) ++ " "
651 then -- trace ("Descent " ++ show (desc - d) ++ " "
652 -- ++ show (path, e)) $
652 -- ++ show (path, e)) $
654− else Partial (Mutual (map (fst . fst) path ++ [f]))
654+ else Partial (Mutual (map (fst . fst . fst) path ++ [f]))
655+ | e `elem` map (fst . fst) path
656+ && not (f `elem` map fst es)
657+ = Partial (Mutual (map (fst . fst . fst) path ++ [f]))
655 | [Unchecked] <- lookupTotal f (tt_ctxt ist) =
658 | [Unchecked] <- lookupTotal f (tt_ctxt ist) =
656 let argspos = case collapseNothing (zip nextargs [0..]) of
659 let argspos = case collapseNothing (zip nextargs [0..]) of
657 [] -> [(Nothing, 0)]
660 [] -> [(Nothing, 0)]
@@ -664,24 +667,24 @@ checkMP ist i mp = if i > 0
664 -- rest definitely terminates without
667 -- rest definitely terminates without
665 -- any cycles with route so far,
668 -- any cycles with route so far,
666 -- then we might yet be total
669 -- then we might yet be total
667− case collapse (map (tryPath (-10000) ((e, 0):path) es)
670+ case collapse (map (tryPath 0 (((e, arg), 0):path) es)
668 [0..length nextargs - 1]) of
671 [0..length nextargs - 1]) of
669 Total _ -> return Unchecked
672 Total _ -> return Unchecked
670 x -> return x
673 x -> return x
671 Just (nextarg, sc) ->
674 Just (nextarg, sc) ->
672 if nextarg == arg then
675 if nextarg == arg then
673 case sc of
676 case sc of
674− Same -> return $ tryPath desc ((e, desc) : path)
677+ Same -> return $ tryPath desc (((e, arg), desc) : path)
676 Smaller -> return $ tryPath (desc+1)
679 Smaller -> return $ tryPath (desc+1)
677− ((e, desc):path)
680+ (((e, arg), desc) : path)
680 _ -> trace ("Shouldn't happen " ++ show e) $
683 _ -> trace ("Shouldn't happen " ++ show e) $
681 return (Partial Itself)
684 return (Partial Itself)
682 else return Unchecked in
685 else return Unchecked in
683-- trace (show (desc, argspos, path, es, pathres)) $
686-- trace (show (desc, argspos, path, es, pathres)) $
684− collapse' Unchecked pathres
687+ collapse' Unchecked pathres
686 | [Total a] <- lookupTotal f (tt_ctxt ist) = Total a
689 | [Total a] <- lookupTotal f (tt_ctxt ist) = Total a
687 | [Partial _] <- lookupTotal f (tt_ctxt ist) = Partial (Other [f])
690 | [Partial _] <- lookupTotal f (tt_ctxt ist) = Partial (Other [f])