- -> [TcIdOcc s]
- -> Int
- -> NF_TcM s (TcExpr s)
-
-makeClassDeclDefaultMethodRhs clas method_ids tag
- = -- Return the expression
- -- error ty "No default method for ..."
- -- The interesting thing is that method_ty is a for-all type;
- -- this is fun, although unusual in a type application!
-
- returnNF_Tc (HsApp (mkHsTyApp (HsVar (RealId nO_DEFAULT_METHOD_ERROR_ID)) [tcIdType method_id])
- (HsLitOut (HsString (_PK_ error_msg)) stringTy))
-
-{- OLD AND COMPLICATED
- tcInstSigType () `thenNF_Tc` \ method_ty ->
- let
- (tyvars, theta, tau) = splitSigmaTy method_ty
- in
- newDicts ClassDeclOrigin theta `thenNF_Tc` \ (lie, dict_ids) ->
-
- returnNF_Tc (mkHsTyLam tyvars (
- mkHsDictLam dict_ids (
- HsApp (mkHsTyApp (HsVar (RealId nO_DEFAULT_METHOD_ERROR_ID)) [tau])
- (HsLitOut (HsString (_PK_ error_msg)) stringTy))))
--}
+ -> 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}