shithub: MicroHs

Download patch

ref: 4bdb0c1286e7999f0dda6df5160337c02bc089b3
parent: dda1943b64afc23dee860b4f058c7f182748b7f7
author: Lennart Augustsson <lennart@augustsson.net>
date: Thu Jan 9 05:19:08 EST 2025

Make sure type variables always point from new to old.

--- a/src/MicroHs/TypeCheck.hs
+++ b/src/MicroHs/TypeCheck.hs
@@ -745,9 +745,11 @@
 
 unifyR :: HasCallStack =>
           SLoc -> EType -> EType -> T ()
-unifyR _   (EVar x1)    (EVar x2)  | x1 == x2      = return ()
+unifyR _   (EVar x1)    (EVar x2)      | x1 == x2  = return ()
 unifyR loc (EApp f1 a1) (EApp f2 a2)               = do { unifyR loc f1 f2; unifyR loc a1 a2 }
-unifyR _   (EUVar r1)   (EUVar r2) | r1 == r2      = return ()
+unifyR loc t1@(EUVar r1) t2@(EUVar r2) | r1 < r2   = unifyVar loc r2 t1   -- always make higher
+                                       | r1 > r2   = unifyVar loc r1 t2   --   TRefs point to lower
+                                       | otherwise = return ()
 unifyR loc (EUVar r1)   t2                         = unifyVar loc r1 t2
 unifyR loc t1           (EUVar r2)                 = unifyVar loc r2 t1
 unifyR loc t1           t2                         = do