@@ -329,15 +329,20 @@ buildSCG' ist sc args = -- trace ("Building SCG for " ++ show sc) $
329329 argRels n = let ctxt = tt_ctxt ist
330330 [ty] = lookupTy n ctxt -- must exist!
331331 P _ nty _ = fst (unApply (getRetTy ty))
332+ co = case lookupCtxt nty (idris_datatypes ist) of
333+ [TI _ x _] -> x
334+ _ -> False
332335 args = map snd (getArgTys ty) in
333− map (getRel nty) (map (fst . unApply . getRetTy) args)
336+ map (getRel co nty) (map (fst . unApply . getRetTy) args)
334337 where
335− getRel ty (P _ n' _) | n' == ty = (n, Smaller)
336− getRel ty t = (n, Unknown)
338+ getRel True _ _ = (n, Unknown) -- coinductive
339+ getRel _ ty (P _ n' _) | n' == ty = (n, Smaller)
340+ getRel _ ty t = (n, Unknown)
337341
338342 scgAlt x vars szs (ConCase n _ args sc)
339343 -- all args smaller than top variable of x in sc
340− -- (as long as they are in the same type family)
344+ -- (as long as they are in the same type family, and it's
345+ -- not coinductive)
341346 | Just tvar <- lookup x vars
342347 = let arel = argRels n
343348 szs' = zipWith (\arg (_,t) -> (arg, (x, t))) args arel