+ where
+ -- Make sure that toplevel type instance are not for associated types.
+ -- !!!TODO: Need to perform this check for the InstInfo structures of type
+ -- functions, too.
+ tcIdxTyInstDeclTL ldecl@(L loc decl) =
+ do { (info, tything) <- tcIdxTyInstDecl ldecl
+ ; setSrcSpan loc $
+ when (isAssocFamily tything) $
+ addErr $ assocInClassErr (tcdName decl)
+ ; return (info, tything)
+ }
+ isAssocFamily (Just (ATyCon tycon)) =
+ case tyConFamInst_maybe tycon of
+ Nothing -> panic "isAssocFamily: no family?!?"
+ Just (fam, _) -> isAssocTyCon fam
+ isAssocFamily (Just _ ) = panic "isAssocFamily: no tycon?!?"
+ isAssocFamily Nothing = False
+
+assocInClassErr name =
+ ptext SLIT("Associated type must be inside class instance") <+>
+ quotes (ppr name)