@@ -423,7 +423,15 @@ buildSCG' ist pats args = nub $ concatMap scgPat pats where
423423 | not (f `elem` pvs) = [(f, [])]
424424 findCalls _ _ _ = []
425425
426− mkChange n args pargs = [(n, sizes args)]
426+ expandToArity n args
427+ = case lookupTy n (tt_ctxt ist) of
428+ [ty] -> expand 0 (normalise (tt_ctxt ist) [] ty) args
429+ _ -> args
430+ where expand i (Bind n (Pi _) sc) (x : xs) = x : expand (i + 1) sc xs
431+ expand i (Bind n (Pi _) sc) [] = Just (i, Same) : expand (i + 1) sc []
432+ expand i _ xs = xs
433+
434+ mkChange n args pargs = [(n, expandToArity n (sizes args))]
427435 where
428436 sizes [] = []
429437 sizes (a : as) = checkSize a pargs 0 : sizes as
@@ -574,12 +582,16 @@ checkSizeChange n = do
574582 -- thread, then the function terminates
575583 -- also need to checks functions called are all total
576584 -- (Unchecked is okay as we'll spot problems here)
577− let tot = map (checkMP ist (length (argsdef cg))) ms
585+ let tot = map (checkMP ist (getArity ist n)) ms
578586 logLvl 4 $ "Generated " ++ show (length tot) ++ " paths"
579587 logLvl 6 $ "Paths for " ++ show n ++ " yield " ++ (show tot)
580588 return (noPartial tot)
581589 [] -> do logLvl 5 $ "No paths for " ++ show n
582590 return Unchecked
591+ where getArity ist n
592+ = case lookupTy n (tt_ctxt ist) of
593+ [ty] -> arity (normalise (tt_ctxt ist) [] ty)
594+ _ -> error "Can't happen: checkSizeChange.getArity"
583595
584596type MultiPath = [SCGEntry]
585597
@@ -609,7 +621,9 @@ mkMultiPaths ist path cg
609621
610622checkMP :: IState -> Int -> MultiPath -> Totality
611623checkMP ist i mp = if i > 0
612− then collapse (map (tryPath 0 [] mp) [0..i-1])
624+ then let paths = (map (tryPath 0 [] mp) [0..i-1]) in
625+-- trace ("Paths " ++ show paths) $
626+ collapse paths
613627 else tryPath 0 [] mp 0
614628 where
615629 tryPath' d path mp arg
@@ -635,12 +649,15 @@ checkMP ist i mp = if i > 0
635649 | Just d <- lookup e path
636650 = if desc > 0
637651 then -- trace ("Descent " ++ show (desc - d) ++ " "
638− -- ++ show (path, e)) $
652+ -- ++ show (path, e)) $
639653 Total []
640654 else Partial (Mutual (map (fst . fst) path ++ [f]))
641655 | [Unchecked] <- lookupTotal f (tt_ctxt ist) =
642− let argspos = collapseNothing (zip nextargs [0..]) in
643− collapse' Unchecked $
656+ let argspos = case collapseNothing (zip nextargs [0..]) of
657+ [] -> [(Nothing, 0)]
658+ x -> x
659+-- trace (show (argspos, nextargs, path)) $
660+ pathres =
644661 do (a, pos) <- argspos
645662 case a of
646663 Nothing -> -- don't know, but if the
@@ -662,7 +679,10 @@ checkMP ist i mp = if i > 0
662679 pos
663680 _ -> trace ("Shouldn't happen " ++ show e) $
664681 return (Partial Itself)
665− else return Unchecked
682+ else return Unchecked in
683+-- trace (show (desc, argspos, path, es, pathres)) $
684+ collapse' Unchecked pathres
685+
666686 | [Total a] <- lookupTotal f (tt_ctxt ist) = Total a
667687 | [Partial _] <- lookupTotal f (tt_ctxt ist) = Partial (Other [f])
668688 | otherwise = Unchecked
@@ -671,8 +691,8 @@ allNothing xs = null (collapseNothing (zip xs [0..]))
671691
672692collapseNothing ((Nothing, _) : xs)
673693 = filter (\ (x, _) -> case x of
674− Nothing -> False
675− _ -> True) xs
694+ Nothing -> False
695+ _ -> True) xs
676696collapseNothing (x : xs) = x : collapseNothing xs
677697collapseNothing [] = []
678698