--- The same function is also used from InstEnv.badFunDeps, when we need
--- to *unify*; in which case the qtvs are the variables of both ls1 and ls2.
--- However unifying with the qtvs being the left-hand lot *is* just matching,
--- so we can call tcUnifyTys in both cases
- = case tcUnifyTys qtvs ls1 ls2 of
- Nothing -> []
- Just unif | maybeToBool (tcUnifyTysX qtvs unif rs1 rs2)
+-- This function is also used when matching two Insts (rather than an Inst
+-- against an instance decl. In that case, qtvs is empty, and we are doing
+-- an equality check
+--
+-- This function is also used by InstEnv.badFunDeps, which needs to *unify*
+-- For the one-sided matching case, the qtvs are just from the template,
+-- so we get matching
+--
+ = ASSERT2( length tys1 == length tys2 &&
+ length tys1 == length clas_tvs
+ , ppr tys1 <+> ppr tys2 )
+
+ case tcUnifyTys bind_fn ls1 ls2 of
+ Nothing -> []
+ Just subst | isJust (tcUnifyTys bind_fn rs1' rs2')