- ; ((tc_bind, _), lie) <- getLIE $
- tcExtendIdEnv [local_meth_id] $
- tcPolyBinds TopLevel meth_sig_fn no_prag_fn
- NonRecursive NonRecursive
- (unitBag bind)
-
- ; let avails = this_dict ++ dfun_dicts
- -- Only need the this_dict stuff if there are type
- -- variables involved; otherwise overlap is not possible
- -- See Note [Subtle interaction of recursion and overlap]
- -- in TcInstDcls
- ; lie_binds <- tcSimplifyCheck inst_loc tyvars avails lie
-
- ; let full_bind = AbsBinds tyvars dfun_lam_vars
- [(tyvars, meth_id, local_meth_id, spec_prags)]
- (this_bind `unionBags` lie_binds
- `unionBags` tc_bind)
-
- dfun_lam_vars = map instToVar dfun_dicts -- Includes equalities
-
- ; return (meth_id, L loc full_bind) }
+ let full_given = case this_dict of
+ Nothing -> dfun_ev_vars
+ Just (EvBind dict _) -> dict : dfun_ev_vars
+ lm_bind = L loc (bind { fun_id = L loc (idName local_meth_id) })
+ -- Substitue the local_meth_name for the binder
+ -- NB: the binding is always a FunBind
+
+ ; (ev_binds, (tc_bind, _))
+ <- checkConstraints skol_info emptyVarSet tyvars full_given $
+ tcExtendIdEnv [local_meth_id] $
+ tcPolyBinds TopLevel meth_sig_fn no_prag_fn
+ NonRecursive NonRecursive
+ [lm_bind]
+
+ -- Add the binding for this_dict, if we have one
+ ; ev_binds' <- case this_dict of
+ Nothing -> return ev_binds
+ Just (EvBind self rhs) -> extendTcEvBinds ev_binds self rhs
+
+ ; 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) }