@@ -77,12 +77,12 @@ unify ctxt env topx topy
77 | holeIn env x = do UI s i f <- get
77 | holeIn env x = do UI s i f <- get
78 when (notP tm && fn) $ put (UI s ((tm, topx, topy) : i) f)
78 when (notP tm && fn) $ put (UI s ((tm, topx, topy) : i) f)
80− return [(x, tm)]
80+ checkCycle (x, tm)
81 un' fn bnames tm (P Bound y _)
81 un' fn bnames tm (P Bound y _)
82 | holeIn env y = do UI s i f <- get
82 | holeIn env y = do UI s i f <- get
83 when (notP tm && fn) $ put (UI s ((tm, topx, topy) : i) f)
83 when (notP tm && fn) $ put (UI s ((tm, topx, topy) : i) f)
85− return [(y, tm)]
85+ checkCycle (y, tm)
86 un' fn bnames (V i) (P Bound x _)
86 un' fn bnames (V i) (P Bound x _)
87 | fst (bnames!!i) == x || snd (bnames!!i) == x = do sc 1; return []
87 | fst (bnames!!i) == x || snd (bnames!!i) == x = do sc 1; return []
88 un' fn bnames (P Bound x _) (V i)
88 un' fn bnames (P Bound x _) (V i)
@@ -165,6 +165,11 @@ unify ctxt env topx topy
165 put (UI s i ((binderTy x, binderTy y, env, err) : f))
165 put (UI s i ((binderTy x, binderTy y, env, err) : f))
166 return [] -- lift $ tfail err
166 return [] -- lift $ tfail err
168+ checkCycle p@(x, P _ _ _) = return [p]
170+ | not (x `elem` freeNames tm) = return [(x, tm)]
171+ | otherwise = lift $ tfail (InfiniteUnify x tm (errEnv env))
168 combine bnames as [] = return as
173 combine bnames as [] = return as
169 combine bnames as ((n, t) : bs)
174 combine bnames as ((n, t) : bs)
170 = case lookup n as of
175 = case lookup n as of