@@ -222,7 +222,7 @@ renameBindersTm env tm = uniqueBinders (map fst env) tm
222222 = Bind n (Hole ty) (instantiate (P Bound n ty) sc)
223223 explicitHole t = t
224224
225−trimSolutions ns = dropPairs ns
225+trimSolutions ns = followSols (dropPairs ns)
226226 where dropPairs [] = []
227227 dropPairs (n@(x, P _ x' _) : ns)
228228 | x == x' = dropPairs ns
@@ -232,7 +232,13 @@ trimSolutions ns = dropPairs ns
232232 (n, P _ n' _) -> not (n == x' && n' == x)
233233 _ -> True) ns)
234234 dropPairs (n : ns) = n : dropPairs ns
235−
235+
236+ followSols [] = []
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
241+
236242expandLets env (x, tm) = (x, doSubst (reverse env) tm)
237243 where
238244 doSubst [] tm = tm