-tcTyClDecl1 is_rec unf_env decl
- | isClassDecl decl = tcAddDeclCtxt decl (tcClassDecl1 is_rec unf_env decl)
- | otherwise = tcAddDeclCtxt decl (tcTyDecl1 is_rec unf_env decl)
+tcTyClDecl1 unf_env decl
+ | isClassDecl decl = tcAddDeclCtxt decl (tcClassDecl1 decl)
+ | otherwise = tcAddDeclCtxt decl (tcTyDecl unf_env decl)
+
+-- We do the validity check over declarations, rather than TyThings
+-- only so that we can add a nice context with tcAddDeclCtxt
+checkValidTyCl this_mod decl
+ = tcLookup (tcdName decl) `thenNF_Tc` \ (AGlobal thing) ->
+ if not (isLocalThing this_mod thing) then
+ -- Don't bother to check validity for non-local things
+ returnTc ()
+ else
+ tcAddDeclCtxt decl $
+ case thing of
+ ATyCon tc -> checkValidTyCon tc
+ AClass cl -> checkValidClass cl