+ -- dm_info = DefMeth dm_name only if there is a binding in binds_in
+
+ dm_sig_fn _ = sig_fn sel_name
+ dm_id = mkDefaultMethodId sel_id dm_name
+ local_dm_type = instantiateMethod clas sel_id (mkTyVarTys tyvars)
+ local_dm_id = mkLocalId local_dm_name local_dm_type
+ prags = prag_fn sel_name
+
+ ; dm_id_w_inline <- addInlinePrags dm_id prags
+ ; spec_prags <- tcSpecPrags dm_id prags
+
+ ; warnTc (not (null spec_prags))
+ (ptext (sLit "Ignoring SPECIALISE pragmas on default method")
+ <+> quotes (ppr sel_name))
+
+ ; liftM Just $
+ tcInstanceMethodBody (ClsSkol clas)
+ tyvars
+ [this_dict]
+ dm_id_w_inline local_dm_id
+ dm_sig_fn IsDefaultMethod meth_bind }
+
+---------------
+tcInstanceMethodBody :: SkolemInfo -> [TcTyVar] -> [EvVar]
+ -> Id -> Id
+ -> SigFun -> TcSpecPrags -> LHsBind Name
+ -> TcM (LHsBind Id)
+tcInstanceMethodBody skol_info tyvars dfun_ev_vars
+ meth_id local_meth_id
+ meth_sig_fn specs
+ (L loc bind)
+ = do { -- Typecheck the binding, first extending the envt
+ -- so that when tcInstSig looks up the local_meth_id to find
+ -- its signature, we'll find it in the environment
+ let lm_bind = L loc (bind { fun_id = L loc (idName local_meth_id) })
+ -- Substitute the local_meth_name for the binder
+ -- NB: the binding is always a FunBind
+
+ ; (ev_binds, (tc_bind, _))
+ <- checkConstraints skol_info tyvars dfun_ev_vars $
+ tcExtendIdEnv [local_meth_id] $
+ tcPolyBinds TopLevel meth_sig_fn no_prag_fn
+ NonRecursive NonRecursive
+ [lm_bind]
+
+ ; let full_bind = AbsBinds { abs_tvs = tyvars, abs_ev_vars = dfun_ev_vars
+ , abs_exports = [(tyvars, meth_id, local_meth_id, specs)]
+ , abs_ev_binds = ev_binds
+ , abs_binds = tc_bind }
+
+ ; return (L loc full_bind) }
+ where
+ no_prag_fn _ = [] -- No pragmas for local_meth_id;
+ -- they are all for meth_id
+\end{code}