@@ -329,15 +329,20 @@ buildSCG' ist sc args = -- trace ("Building SCG for " ++ show sc) $
329 argRels n = let ctxt = tt_ctxt ist
329 argRels n = let ctxt = tt_ctxt ist
330 [ty] = lookupTy n ctxt -- must exist!
330 [ty] = lookupTy n ctxt -- must exist!
331 P _ nty _ = fst (unApply (getRetTy ty))
331 P _ nty _ = fst (unApply (getRetTy ty))
332+ co = case lookupCtxt nty (idris_datatypes ist) of
332 args = map snd (getArgTys ty) in
335 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)
338+ getRel True _ _ = (n, Unknown) -- coinductive
335− getRel ty (P _ n' _) | n' == ty = (n, Smaller)
339+ getRel _ ty (P _ n' _) | n' == ty = (n, Smaller)
336− getRel ty t = (n, Unknown)
340+ getRel _ ty t = (n, Unknown)
338 scgAlt x vars szs (ConCase n _ args sc)
342 scgAlt x vars szs (ConCase n _ args sc)
339 -- all args smaller than top variable of x in sc
343 -- 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
341 | Just tvar <- lookup x vars
346 | Just tvar <- lookup x vars
342 = let arel = argRels n
347 = let arel = argRels n
343 szs' = zipWith (\arg (_,t) -> (arg, (x, t))) args arel
348 szs' = zipWith (\arg (_,t) -> (arg, (x, t))) args arel