[project @ 2005-01-18 15:58:12 by simonpj]
[ghc-hetmet.git] / ghc / compiler / types / InstEnv.lhs
index 5b41bf9..965ba55 100644 (file)
@@ -17,7 +17,7 @@ module InstEnv (
 #include "HsVersions.h"
 
 import Class           ( Class, classTvsFds )
-import Var             ( Id )
+import Var             ( Id, isTcTyVar )
 import VarSet
 import Type            ( TvSubst )
 import TcType          ( Type, tcTyConAppTyCon, tcIsTyVarTy,
@@ -322,12 +322,18 @@ lookup_inst_env env key_cls key_tys key_all_tvs
          Nothing 
                -- Does not match, so next check whether the things unify
                -- [see notes about overlapping instances above]
-          -> case tcUnifyTys bind_fn tpl key_tys of
+          -> ASSERT2( not (tyVarsOfTypes key_tys `intersectsVarSet` tpl_tyvars),
+                      (ppr key_cls <+> ppr key_tys <+> ppr key_all_tvs) $$
+                      (ppr dfun_id <+> ppr tpl_tyvars <+> ppr tpl)
+                     )
+               -- Unification will break badly if the variables overlap
+               -- They shouldn't because we allocate separate uniques for them
+             case tcUnifyTys bind_fn tpl key_tys of
                Just _   -> find rest ms (dfun_id:us)
                Nothing  -> find rest ms us
 
-    bind_fn tv | isExistentialTyVar tv = Skolem
-              | otherwise             = BindMe
+    bind_fn tv | isTcTyVar tv && isExistentialTyVar tv = Skolem
+              | otherwise                             = BindMe
        -- The key_tys can contain skolem constants, and we can guarantee that those
        -- are never going to be instantiated to anything, so we should not involve
        -- them in the unification test.  Example: