Add a warning flag for when the Prelude is implicitly imported (trac #1317)
[ghc-hetmet.git] / compiler / rename / RnNames.lhs
index 70150ca..4a880ed 100644 (file)
@@ -13,7 +13,7 @@ module RnNames (
 
 #include "HsVersions.h"
 
-import DynFlags                ( DynFlag(..), GhcMode(..), DynFlags(..) )
+import DynFlags
 import HsSyn           ( IE(..), ieName, ImportDecl(..), LImportDecl,
                          ForeignDecl(..), HsGroup(..), HsValBinds(..),
                          Sig(..), collectHsBindLocatedBinders, tyClDeclNames,
@@ -69,6 +69,10 @@ rnImports imports
              (source, ordinary) = partition is_source_import imports
              is_source_import (L _ (ImportDecl _ is_boot _ _ _)) = is_boot
 
+         ifOptM Opt_WarnImplicitPrelude (
+            when (notNull prel_imports) $ addWarn (implicitPreludeWarn)
+          )
+
          stuff1 <- mapM (rnImportDecl this_mod) (prel_imports ++ ordinary)
          stuff2 <- mapM (rnImportDecl this_mod) source
          let (decls, rdr_env, imp_avails) = combine (stuff1 ++ stuff2)
@@ -708,10 +712,10 @@ rnExports explicit_mod exports
        -- written "module Main where ..."
        -- Reason: don't want to complain about 'main' not in scope
        --         in interactive mode
-       ; ghc_mode <- getGhcMode
+        ; dflags <- getDOpts
        ; let real_exports 
-                | explicit_mod            = exports
-                | ghc_mode == Interactive = Nothing
+                | explicit_mod = exports
+                | ghcLink dflags == LinkInMemory = Nothing
                 | otherwise = Just ([noLoc (IEVar main_RDR_Unqual)])
                        -- ToDo: the 'noLoc' here is unhelpful if 'main' 
                        --       turns out to be out of scope
@@ -1355,4 +1359,7 @@ nullModuleExport mod
 moduleDeprec mod txt
   = sep [ ptext SLIT("Module") <+> quotes (ppr mod) <+> ptext SLIT("is deprecated:"), 
          nest 4 (ppr txt) ]      
+
+implicitPreludeWarn
+  = ptext SLIT("Module `Prelude' implicitly imported")
 \end{code}