@@ -410,18 +410,20 @@ delazy' all t@(App f a)
410410 l == txt "Force" = delazy' all arg
411411 | (P _ (UN l) _, [P _ (UN lty) _, _, arg]) <- unApply t,
412412 l == txt "Delay" && (all || lty == txt "LazyEval") = delazy arg
413− | (P _ (UN l) _, [_, arg]) <- unApply t,
414− l == txt "Lazy'" = delazy' all arg
413+ | (P _ (UN l) _, [P _ (UN lty) _, arg]) <- unApply t,
414+ l == txt "Lazy'" && (all || lty == txt "LazyEval") = delazy' all arg
415415delazy' all (App f a) = App (delazy' all f) (delazy' all a)
416416delazy' all (Bind n b sc) = Bind n (fmap (delazy' all) b) (delazy' all sc)
417417delazy' all t = t
418418
419+data Guardedness = Toplevel | Unguarded | Guarded
420+
419421buildSCG' :: IState -> [(Term, Term)] -> [Name] -> [SCGEntry]
420422buildSCG' ist pats args = nub $ concatMap scgPat pats where
421423 scgPat (lhs, rhs) = let lhs' = delazy lhs
422424 rhs' = delazy rhs
423425 (f, pargs) = unApply (dePat lhs') in
424− findCalls True (dePat rhs') (patvars lhs') pargs
426+ findCalls Toplevel (dePat rhs') (patvars lhs') pargs
425427
426428 findCalls guarded ap@(App f a) pvs pargs
427429 -- under a call to "assert_total", don't do any checking, just believe
@@ -431,15 +433,20 @@ buildSCG' ist pats args = nub $ concatMap scgPat pats where
431433 -- under a call to "Delay LazyCodata", don't do any checking as long
432434 -- as the call is guarded
433435 | (P _ (UN del) _, [_,_,_]) <- unApply ap,
434− guarded && del == txt "Delay" = []
436+ guarded <- Guarded,
437+ del == txt "Delay" = []
435438 | (P _ n _, args) <- unApply ap
436− = let nguarded = isConName n (tt_ctxt ist) in
439+ = let nguarded = case guarded of
440+ Unguarded -> Unguarded
441+ _ -> if isConName n (tt_ctxt ist)
442+ then Guarded
443+ else Unguarded in
437444 mkChange n args pargs ++
438445 concatMap (\x -> findCalls nguarded x pvs pargs) args
439446 findCalls guarded (App f a) pvs pargs
440− = findCalls False f pvs pargs ++ findCalls False a pvs pargs
447+ = findCalls Unguarded f pvs pargs ++ findCalls Unguarded a pvs pargs
441448 findCalls guarded (Bind n (Let t v) e) pvs pargs
442− = findCalls False v pvs pargs ++ findCalls guarded e (n : pvs) pargs
449+ = findCalls Unguarded v pvs pargs ++ findCalls guarded e (n : pvs) pargs
443450 findCalls guarded (Bind n _ e) pvs pargs
444451 = findCalls guarded e (n : pvs) pargs
445452 findCalls guarded (P _ f _ ) pvs pargs