dollarMainName, itName, mAIN_Name
)
import MkId ( unsafeCoerceId )
-import RdrName ( RdrName, getRdrName, mkUnqual, mkRdrUnqual,
+import RdrName ( RdrName, getRdrName, mkRdrUnqual,
lookupRdrEnv, elemRdrEnv )
import RnHsSyn ( RenamedStmt, RenamedTyClDecl,
import TcBinds ( tcTopBinds )
import TcClassDcl ( tcClassDecls2 )
import TcDefaults ( tcDefaults )
-import TcEnv ( RecTcGblEnv,
- tcExtendGlobalValEnv,
+import TcEnv ( tcExtendGlobalValEnv,
tcExtendGlobalEnv,
tcExtendInstEnv, tcExtendRules,
tcLookupTyCon, tcLookupGlobal,
import TcSimplify ( tcSimplifyTop, tcSimplifyInfer )
import TcTyClsDecls ( tcTyAndClassDecls )
-import RnNames ( rnImports, exportsFromAvail, reportUnusedNames )
+import RnNames ( importsFromLocalDecls, rnImports, exportsFromAvail,
+ reportUnusedNames, main_RDR_Unqual )
import RnIfaces ( slurpImpDecls, checkVersions, RecompileRequired, outOfDate )
import RnHiFiles ( readIface, loadOldIface )
import RnEnv ( lookupSrcName, lookupOccRn, plusGlobalRdrEnv,
ubiquitousNames, implicitModuleFVs, implicitStmtFVs, dataTcOccs )
import RnExpr ( rnStmts, rnExpr )
-import RnNames ( importsFromLocalDecls )
import RnSource ( rnSrcDecls, checkModDeprec, rnStats )
-import OccName ( varName )
import CoreUnfold ( unfoldingTemplate )
import CoreSyn ( IdCoreRule, Bind(..) )
import PprCore ( pprIdRules, pprCoreBindings )
updGblEnv (\gbl -> gbl { tcg_exports = export_avails })
$ do {
- -- Get the supporting decls for the exports
- -- This is important *only* to gether usage information
+ -- Get any supporting decls for the exports that have not already
+ -- been sucked in for the declarations in the body of the module.
+ -- (This can happen if something is imported only to be re-exported.)
+ --
+ -- Importing these supporting declarations is required
+ -- *only* to gether usage information
-- (see comments with MkIface.mkImportInfo for why)
-- For OneShot compilation we could just throw away the decls
-- but for Batch or Interactive we must put them in the type
| mod_name /= mAIN_Name
= return (tcg_env, emptyFVs)
+ -- Check that 'main' is in scope
+ -- It might be imported from another module!
+ --
+ -- We use a guard for this (rather than letting lookupSrcName fail)
+ -- because it's not an error in ghci)
| not (main_RDR_Unqual `elemRdrEnv` rdr_env)
= do { complain_no_main; return (tcg_env, emptyFVs) }
| otherwise
- = do { -- Check that 'main' is in scope
- -- It might be imported from another module!
- main_name <- lookupSrcName main_RDR_Unqual ;
- failIfErrsM ;
+ = do { main_name <- lookupSrcName main_RDR_Unqual ;
tcg_env <- importSupportingDecls (unitFV runIOName) ;
setGblEnv tcg_env $ do {
mod_name = moduleName (tcg_mod tcg_env)
rdr_env = tcg_rdr_env tcg_env
- main_RDR_Unqual :: RdrName
- main_RDR_Unqual = mkUnqual varName FSLIT("main")
- -- Don't get a RdrName from PrelNames.mainName, because
- -- nameRdrNamegets an Orig RdrName, and we want a Qual or Unqual one.
- -- An Unqual one will do just fine
-
complain_no_main | ghci_mode == Interactive = return ()
- | otherwise = addErr noMainMsg
+ | otherwise = failWithTc noMainMsg
-- In interactive mode, don't worry about the absence of 'main'
+ -- In other modes, fail altogether, so that we don't go on
+ -- and complain a second time when processing the export list.
mainCtxt = ptext SLIT("When checking the type of 'main'")
noMainMsg = ptext SLIT("No 'main' defined in module Main")