- tcGetEnv `thenNF_Tc` \ env ->
- returnTc (tycls_details, all_tyclss, env)
- ) `thenTc` \ (_, all_tyclss, env) ->
-
- tcSetEnv env $
-
- -- Step 6
- -- For a recursive group, check all the types again,
- -- this time with the wimp flag off
- (if isRec is_rec then
- mapTc_ (tcTyClDecl1 NonRecursive unf_env) decls
- else
- returnTc ()
- ) `thenTc_`
-
- -- Step 7
- -- Extend the environment with the final TyCons/Classes
- -- and their implicit Ids
- tcExtendGlobalValEnv (implicitTyThingIds all_tyclss) tcGetEnv
+ getGblEnv `thenM` \ env ->
+ returnM (tycls_details, env, tyclss)
+ ) `thenM` \ (_, env, tyclss) ->
+
+ -- Step 7: Check validity
+ traceTc (text "ready for validity check") `thenM_`
+ getModule `thenM` \ mod ->
+ setGblEnv env (
+ mappM_ (checkValidTyCl mod) decls
+ ) `thenM_`
+ traceTc (text "done") `thenM_`
+
+ let -- Add the tycons that come from the classes
+ -- We want them in the environment because
+ -- they are mentioned in interface files
+ implicit_tycons, implicit_ids, all_tyclss :: [TyThing]
+ implicit_tycons = [ATyCon (classTyCon clas) | AClass clas <- tyclss]
+ all_tyclss = implicit_tycons ++ tyclss
+ implicit_ids = [AnId id | id <- implicitTyThingIds all_tyclss]
+ new_things = implicit_ids ++ all_tyclss
+ in
+ returnM (env, new_things)