@@ -630,12 +630,12 @@ checkMP ist i mp = if i > 0
630630 = let res = tryPath d path mp arg in
631631 trace (show mp ++ "\n" ++ show arg ++ " " ++ show res) res
632632
633− tryPath :: Int -> [(SCGEntry, Int)] -> MultiPath -> Int -> Totality
633+ tryPath :: Int -> [((SCGEntry, Int), Int)] -> MultiPath -> Int -> Totality
634634 tryPath desc path [] _ = Total []
635635-- tryPath desc path ((UN "believe_me", _) : _) arg
636636-- = Partial BelieveMe
637637 -- 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
639639 | [TyDecl (DCon _ _) _] <- lookupDef f (tt_ctxt ist)
640640 = case lookupTotal f (tt_ctxt ist) of
641641 [Total _] -> Unchecked -- okay so far
@@ -646,12 +646,15 @@ checkMP ist i mp = if i > 0
646646 tryPath desc path (e@(f, args) : es) arg
647647 | e `elem` es && allNothing args = Partial (Mutual [f])
648648 tryPath desc path (e@(f, nextargs) : es) arg
649− | Just d <- lookup e path
649+ | Just d <- lookup (e, arg) path
650650 = if desc > 0
651651 then -- trace ("Descent " ++ show (desc - d) ++ " "
652652 -- ++ show (path, e)) $
653653 Total []
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]))
655658 | [Unchecked] <- lookupTotal f (tt_ctxt ist) =
656659 let argspos = case collapseNothing (zip nextargs [0..]) of
657660 [] -> [(Nothing, 0)]
@@ -664,24 +667,24 @@ checkMP ist i mp = if i > 0
664667 -- rest definitely terminates without
665668 -- any cycles with route so far,
666669 -- 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)
668671 [0..length nextargs - 1]) of
669672 Total _ -> return Unchecked
670673 x -> return x
671674 Just (nextarg, sc) ->
672675 if nextarg == arg then
673676 case sc of
674− Same -> return $ tryPath desc ((e, desc) : path)
677+ Same -> return $ tryPath desc (((e, arg), desc) : path)
675678 es pos
676679 Smaller -> return $ tryPath (desc+1)
677− ((e, desc):path)
680+ (((e, arg), desc) : path)
678681 es
679682 pos
680683 _ -> trace ("Shouldn't happen " ++ show e) $
681684 return (Partial Itself)
682685 else return Unchecked in
683686-- trace (show (desc, argspos, path, es, pathres)) $
684− collapse' Unchecked pathres
687+ collapse' Unchecked pathres
685688
686689 | [Total a] <- lookupTotal f (tt_ctxt ist) = Total a
687690 | [Partial _] <- lookupTotal f (tt_ctxt ist) = Partial (Other [f])