+\begin{code}
+tcMethodBind
+ :: Class
+ -> InstOrigin s
+ -> [TcType s] -- Instance types
+ -> [TcTyVar s] -- Free variables of those instance types
+ -- they'll be signature tyvars, and we
+ -- want to check that they don't bound
+ -> Id -- The method selector
+ -> RenamedMonoBinds -- Method binding (just one)
+ -> TcM s (TcMonoBinds s, LIE s, (LIE s, TcIdOcc s))
+
+tcMethodBind clas origin inst_tys inst_tyvars sel_id meth_bind
+ = tcAddSrcLoc src_loc $
+ newMethod origin (RealId sel_id) inst_tys `thenNF_Tc` \ meth@(_, TcId local_meth_id) ->
+ tcInstSigTcType (idType local_meth_id) `thenNF_Tc` \ (tyvars', rho_ty') ->
+ let
+ (theta', tau') = splitRhoTy rho_ty'
+ sig_info = TySigInfo bndr_name local_meth_id tyvars' theta' tau' src_loc
+ in
+ tcExtendGlobalTyVars inst_tyvars (
+ tcAddErrCtxt (methodCtxt sel_id) $
+ tcBindWithSigs NotTopLevel [bndr_name] meth_bind [sig_info]
+ NonRecursive (\_ -> NoPragmaInfo)
+ ) `thenTc` \ (binds, insts, _) ->
+
+ -- Now check that the instance type variables
+ -- (or, in the case of a class decl, the class tyvars)
+ -- have not been unified with anything in the environment
+ tcAddErrCtxt (monoCtxt sel_id) (
+ tcAddErrCtxt (sigCtxt sel_id) $
+ checkSigTyVars inst_tyvars (idType local_meth_id)
+ ) `thenTc_`
+
+ returnTc (binds, insts, meth)
+ where
+ (bndr_name, src_loc) = case meth_bind of
+ FunMonoBind name _ _ loc -> (name, loc)
+ PatMonoBind (VarPatIn name) _ loc -> (name, loc)
+\end{code}