import MkId ( mkDefaultMethodId, mkDictFunId )
import Id ( Id, idType, idName, mkUserLocal, setInlinePragma )
import Name ( Name, NamedThing(..) )
-import NameEnv ( NameEnv, lookupNameEnv, emptyNameEnv, unitNameEnv,
- plusNameEnv, mkNameEnv )
+import NameEnv ( NameEnv, lookupNameEnv, mkNameEnv )
import NameSet ( emptyNameSet, unitNameSet, nameSetToList )
import OccName ( reportIfUnused, mkDefaultMethodOcc )
import RdrName ( RdrName, mkDerivedRdrName )
import Util ( count, lengthIs, isSingleton, lengthExceeds )
import Unique ( Uniquable(..) )
import ListSetOps ( equivClassesByUniq, minusList )
-import SrcLoc ( SrcLoc, Located(..), srcSpanStart, unLoc, noLoc )
+import SrcLoc ( Located(..), srcSpanStart, unLoc, noLoc )
import Maybes ( seqMaybe, isJust, mapCatMaybes )
import List ( partition )
import Bag
tcMethodBind xtve inst_tyvars inst_theta avail_insts prags
(sel_id, meth_id, meth_bind)
- = -- Check the bindings; first adding inst_tyvars to the envt
+ = recoverM (returnM emptyBag) $
+ -- If anything fails, recover returning no bindings.
+ -- This is particularly useful when checking the default-method binding of
+ -- a class decl. If we don't recover, we don't add the default method to
+ -- the type enviroment, and we get a tcLookup failure on $dmeth later.
+
+ -- Check the bindings; first adding inst_tyvars to the envt
-- so that we don't quantify over them in nested places
mkTcSig meth_id `thenM` \ meth_sig ->
\begin{code}
getGenericInstances :: [LTyClDecl Name] -> TcM [InstInfo]
getGenericInstances class_decls
- = do { gen_inst_infos <- mappM get_generics class_decls
+ = do { gen_inst_infos <- mappM (addLocM get_generics) class_decls
; let { gen_inst_info = concat gen_inst_infos }
-- Return right away if there is no generic stuff
(vcat (map pprInstInfoDetails gen_inst_info)))
; returnM gen_inst_info }}
-get_generics decl@(L loc (ClassDecl {tcdLName = class_name, tcdMeths = def_methods}))
+get_generics decl@(ClassDecl {tcdLName = class_name, tcdMeths = def_methods})
| null generic_binds
= returnM [] -- The comon case: no generic default methods
let
groups = groupWith listToBag generic_binds
in
- mappM (mkGenericInstance clas (srcSpanStart loc)) groups
- `thenM` \ inst_infos ->
+ mappM (mkGenericInstance clas) groups `thenM` \ inst_infos ->
-- Check that there is only one InstInfo for each type constructor
-- The main way this can fail is if you write
eqPatType _ _ = False
---------------------------------
-mkGenericInstance :: Class -> SrcLoc
+mkGenericInstance :: Class
-> (HsType Name, LHsBinds Name)
-> TcM InstInfo
-mkGenericInstance clas loc (hs_ty, binds)
+mkGenericInstance clas (hs_ty, binds)
-- Make a generic instance declaration
-- For example: instance (C a, C b) => C (a+b) where { binds }
(badGenericInstanceType binds) `thenM_`
-- Make the dictionary function.
- newDFunName clas [inst_ty] loc `thenM` \ dfun_name ->
+ getSrcSpanM `thenM` \ span ->
+ newDFunName clas [inst_ty] (srcSpanStart span) `thenM` \ dfun_name ->
let
inst_theta = [mkClassPred clas [mkTyVarTy tv] | tv <- tyvars]
dfun_id = mkDictFunId dfun_name tyvars inst_theta clas [inst_ty]
%************************************************************************
\begin{code}
-tcAddDeclCtxt (L loc decl) thing_inside
- = addSrcSpan loc $
- addErrCtxt ctxt $
- thing_inside
+tcAddDeclCtxt decl thing_inside
+ = addErrCtxt ctxt thing_inside
where
thing = case decl of
ClassDecl {} -> "class"