+tcMethodBind origin inst_tyvars inst_theta
+ this_dict extra_insts
+ sig_fn prag_fn meth_binds
+ (sel_id, dm_info) meth_id
+ | Just user_bind <- find_bind sel_name meth_name meth_binds
+ = -- If there is a user-supplied method binding, typecheck it
+ tc_method_bind inst_tyvars inst_theta (this_dict:extra_insts)
+ sig_fn prag_fn
+ sel_id meth_id user_bind
+
+ | otherwise -- The user didn't supply a method binding, so we have to make
+ -- up a default binding, in a way depending on the default-method info
+ = case dm_info of
+ NoDefMeth -> do { warn <- doptM Opt_WarnMissingMethods
+ ; warnTc (isInstDecl origin
+ && warn -- Warn only if -fwarn-missing-methods
+ && reportIfUnused (getOccName sel_id))
+ -- Don't warn about _foo methods
+ (omittedMethodWarn sel_id)
+ ; return (unitBag $ L loc (VarBind meth_id error_rhs)) }
+
+ DefMeth -> do { -- An polymorphic default method
+ -- Might not be imported, but will be an OrigName
+ dm_name <- lookupImportedName (mkDefMethRdrName sel_id)
+ ; dm_id <- tcLookupId dm_name
+ -- Note [Default methods in instances]
+ ; return (unitBag $ L loc (VarBind meth_id (mk_dm_app dm_id))) }
+
+ GenDefMeth -> ASSERT( isInstDecl origin ) -- We never get here from a class decl
+ do { meth_bind <- mkGenericDefMethBind clas inst_tys sel_id meth_name
+ ; tc_method_bind inst_tyvars inst_theta (this_dict:extra_insts)
+ sig_fn prag_fn
+ sel_id meth_id meth_bind }
+
+ where
+ meth_name = idName meth_id
+ sel_name = idName sel_id
+ loc = getSrcSpan meth_id
+ (clas, inst_tys) = getDictClassTys this_dict
+
+ this_dict_id = instToId this_dict
+ error_id = L loc (HsVar nO_METHOD_BINDING_ERROR_ID)
+ error_id_app = mkLHsWrap (WpTyApp (idType meth_id)) error_id
+ error_rhs = mkHsApp error_id_app $ L loc $
+ HsLit (HsStringPrim (mkFastString error_msg))
+ error_msg = showSDoc (hcat [ppr loc, text "|", ppr sel_id ])
+
+ mk_dm_app dm_id -- dm tys inst_dict
+ = mkLHsWrap (WpApp this_dict_id `WpCompose` mkWpTyApps inst_tys)
+ (L loc (HsVar dm_id))
+
+
+---------------------------
+tc_method_bind :: [TyVar] -> TcThetaType -> [Inst] -> (Name -> Maybe [Name])
+ -> (Name -> [LSig Name]) -> Id -> Id -> LHsBind Name
+ -> TcRn (LHsBindsLR Id Var)
+tc_method_bind inst_tyvars inst_theta avail_insts sig_fn prag_fn
+ sel_id meth_id meth_bind
+ = recoverM (return emptyLHsBinds) $