@@ -222,7 +222,7 @@ renameBindersTm env tm = uniqueBinders (map fst env) tm
222 = Bind n (Hole ty) (instantiate (P Bound n ty) sc)
222 = Bind n (Hole ty) (instantiate (P Bound n ty) sc)
223 explicitHole t = t
223 explicitHole t = t
225−trimSolutions ns = dropPairs ns
225+trimSolutions ns = followSols (dropPairs ns)
226 where dropPairs [] = []
226 where dropPairs [] = []
227 dropPairs (n@(x, P _ x' _) : ns)
227 dropPairs (n@(x, P _ x' _) : ns)
228 | x == x' = dropPairs ns
228 | x == x' = dropPairs ns
@@ -232,7 +232,13 @@ trimSolutions ns = dropPairs ns
232 (n, P _ n' _) -> not (n == x' && n' == x)
232 (n, P _ n' _) -> not (n == x' && n' == x)
233 _ -> True) ns)
233 _ -> True) ns)
234 dropPairs (n : ns) = n : dropPairs ns
234 dropPairs (n : ns) = n : dropPairs ns
237+ followSols ((n, P _ t _) : ns)
238+ | Just t' <- lookup t ns
239+ = followSols ((n, t') : ns) -- Are we guaranteed no cycles?
240+ followSols (n : ns) = n : followSols ns
236expandLets env (x, tm) = (x, doSubst (reverse env) tm)
242expandLets env (x, tm) = (x, doSubst (reverse env) tm)
238 doSubst [] tm = tm
244 doSubst [] tm = tm