- -- so that when tcInstSig looks up the meth_id to find
- -- its signature, we'll find it in the environment
- --
- -- If scoped type variables is on, they are brought
- -- into scope by tcPolyBinds (via sig_fn)
- --
- -- See Note [Polymorphic methods]
- ; traceTc (text "tcMethodBind" <+> ppr meth_id <+> ppr tyvars)
- ; (tc_binds, ids) <- tcExtendIdEnv [meth_id] $
- tcPolyBinds TopLevel sig_fn prag_fn
- NonRecursive NonRecursive
- (unitBag bind)
-
- ; ASSERT( ids == [meth_id] ) -- Binding for ONE method
- return tc_binds }
+ -- so that when tcInstSig looks up the local_meth_id to find
+ -- its signature, we'll find it in the environment
+ ; ((tc_bind, _), lie) <- getLIE $
+ tcExtendIdEnv [local_meth_id] $
+ tcPolyBinds TopLevel sig_fn prag_fn
+ NonRecursive NonRecursive
+ (unitBag bind)
+
+ ; meth_id <- case rigid_info of
+ ClsSkol _ -> do { dm_name <- lookupTopBndrRn (mkDefMethRdrName sel_name)
+ ; return (mkDefaultMethodId dm_name meth_ty) }
+ _other -> do { meth_name <- newLocalName sel_name
+ ; return (mkLocalId meth_name meth_ty) }
+
+ ; let (avails, this_dict_bind)
+ = case mb_this_bind of
+ Nothing -> (dfun_dicts, emptyBag)
+ Just (this, bind) -> (this : dfun_dicts, unitBag bind)
+
+ ; inst_loc <- getInstLoc (SigOrigin rigid_info)
+ ; lie_binds <- tcSimplifyCheck inst_loc tyvars avails lie
+
+ ; let full_bind = L loc $
+ AbsBinds tyvars dfun_lam_vars
+ [(tyvars, meth_id, local_meth_id, [])]
+ (this_dict_bind `unionBags` lie_binds
+ `unionBags` tc_bind)
+
+ dfun_lam_vars = map instToVar dfun_dicts -- Includes equalities
+
+ ; return (meth_id, unitBag full_bind) }