+ -- It's important to add the in-scope tyvars to the global tyvar set
+ -- as well. Consider
+ -- f (x::r) = let g y = y::r in ...
+ -- Here, g mustn't be generalised. This is also important during
+ -- class and instance decls, when we mustn't generalise the class tyvars
+ -- when typechecking the methods.
+ tc_extend_gtvs gtvs new_tv_set `thenNF_Tc` \ gtvs' ->
+ tcSetEnv (TcEnv te' ve (in_scope_tvs', gtvs')) scope
+
+-- This variant, tcExtendTyVarEnvForMeths, takes *two* bunches of tyvars:
+-- the signature tyvars contain the original names
+-- the instance tyvars are what those names should be mapped to
+-- It's needed when typechecking the method bindings of class and instance decls
+-- It does *not* extend the global tyvars; tcMethodBind does that for itself
+
+tcExtendTyVarEnvForMeths :: [TyVar] -> [TcTyVar] -> TcM s r -> TcM s r
+tcExtendTyVarEnvForMeths sig_tyvars inst_tyvars thing_inside
+ = tcGetEnv `thenNF_Tc` \ (TcEnv te ve gtvs) ->
+ let
+ te' = addListToUFM te stuff
+ in
+ tcSetEnv (TcEnv te' ve gtvs) thing_inside
+ where
+ stuff = [ (getName sig_tv, (kindToTcKind (tyVarKind inst_tv), Nothing, ATyVar inst_tv))
+ | (sig_tv, inst_tv) <- zipEqual "tcMeth" sig_tyvars inst_tyvars
+ ]