X-Git-Url: http://git.megacz.com/?a=blobdiff_plain;f=compiler%2Ftypecheck%2FTcEnv.lhs;h=ff49db6af6b04448f5a032cbb551f2d397b58b4a;hb=cdce647711c0f46f5799b24de087622cb77e647f;hp=d59278a26357a881769db37943203ea7f17addf2;hpb=380512de6eef0cbb17431d9e64007a9320914e23;p=ghc-hetmet.git diff --git a/compiler/typecheck/TcEnv.lhs b/compiler/typecheck/TcEnv.lhs index d59278a..ff49db6 100644 --- a/compiler/typecheck/TcEnv.lhs +++ b/compiler/typecheck/TcEnv.lhs @@ -160,15 +160,30 @@ tcLookupLocatedTyCon :: Located Name -> TcM TyCon tcLookupLocatedTyCon = addLocM tcLookupTyCon -- Look up the representation tycon of a family instance. --- -tcLookupFamInst :: TyCon -> [Type] -> TcM TyCon +-- Return the rep tycon and the corresponding rep args +tcLookupFamInst :: TyCon -> [Type] -> TcM (TyCon, [Type]) tcLookupFamInst tycon tys + | not (isOpenTyCon tycon) + = return (tycon, tys) + | otherwise = do { env <- getGblEnv ; eps <- getEps ; let instEnv = (eps_fam_inst_env eps, tcg_fam_inst_env env) - ; case lookupFamInstEnvExact instEnv tycon tys of - Nothing -> famInstNotFound tycon tys - Just famInst -> return $ famInstTyCon famInst + ; case lookupFamInstEnv instEnv tycon tys of + + [(subst, fam_inst)] | variable_only_subst -> + return (rep_tc, substTyVars subst (tyConTyVars rep_tc)) + where -- NB: assumption is that (tyConTyVars rep_tc) is in + -- the domain of the substitution + rep_tc = famInstTyCon fam_inst + subst_domain = varEnvElts . getTvSubstEnv $ subst + tvs = map (Type.getTyVar "tcLookupFamInst") + subst_domain + variable_only_subst = all Type.isTyVarTy subst_domain && + sizeVarSet (mkVarSet tvs) == length tvs + -- renaming may have no repetitions + + other -> famInstNotFound tycon tys other } \end{code} @@ -670,8 +685,10 @@ wrongThingErr expected thing name = failWithTc (pprTcTyThingCategory thing <+> quotes (ppr name) <+> ptext SLIT("used as a") <+> text expected) -famInstNotFound tycon tys - = failWithTc (quotes famInst <+> ptext SLIT("is not in scope")) +famInstNotFound tycon tys what + = failWithTc (msg <+> quotes (pprTypeApp (ppr tycon) tys)) where - famInst = ppr tycon <+> hsep (map pprParendType tys) + msg = ptext $ if length what > 1 + then SLIT("More than one family instance for") + else SLIT("No family instance exactly matching") \end{code}