- ; 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