-importsFromImportDeclDirect :: Module
- -> LImportDecl RdrName
- -> RnM (LImportDecl Name)
-importsFromImportDeclDirect this_mod
- (L loc importDecl@(ImportDecl loc_imp_mod_name want_boot qual_only as_mod imp_details))
- = setSrcSpan loc $
- do iface <- loadSrcInterface doc imp_mod_name want_boot
- let filtered_exports = filter not_this_mod (mi_exports iface)
- not_this_mod (mod,_) = mod /= this_mod
-
- -- If the module exports anything defined in this module, just ignore it.
- -- Reason: otherwise it looks as if there are two local definition sites
- -- for the thing, and an error gets reported. Easiest thing is just to
- -- filter them out up front. This situation only arises if a module
- -- imports itself, or another module that imported it. (Necessarily,
- -- this invoves a loop.)
- --
- -- Tiresome consequence: if you say
- -- module A where
- -- import B( AType )
- -- type AType = ...
- --
- -- module B( AType ) where
- -- import {-# SOURCE #-} A( AType )
- --
- -- then you'll get a 'B does not export AType' message. Oh well.
-
- qual_mod_name = case as_mod of
- Nothing -> imp_mod_name
- Just another_name -> another_name
- imp_spec = ImpDeclSpec { is_mod = imp_mod_name, is_qual = qual_only,
- is_dloc = loc, is_as = qual_mod_name }
-
- -- Get the total imports, and filter them according to the import list
- total_avails <- ifaceExportNames (mi_exports iface)
- importDecl' <- rnImportDecl iface imp_spec importDecl total_avails
- return (L loc importDecl')
- where imp_mod_name = unLoc loc_imp_mod_name
- doc = ppr imp_mod_name <+> ptext SLIT("is directly imported")
-