summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIsaac Dupree <id@isaac.cedarswampstudios.org>2007-05-11 08:45:25 +0000
committerIsaac Dupree <id@isaac.cedarswampstudios.org>2007-05-11 08:45:25 +0000
commit536852b1348fde6ec0ba13859cc5ddf8480a1653 (patch)
tree3d442de92d95ac7c989616c8927fd4dfb705606c
parent53167b89a0ad08049ed429e09d6863b6b322ec44 (diff)
downloadhaskell-536852b1348fde6ec0ba13859cc5ddf8480a1653.tar.gz
Add a warning flag for when the Prelude is implicitly imported (trac #1317)
GHC already determines all the implicit (Prelude) imports, so we just need to check whether there are any of those, for each module being compiled.
-rw-r--r--compiler/main/DynFlags.hs2
-rw-r--r--compiler/rename/RnNames.lhs7
-rw-r--r--docs/users_guide/flags.xml9
-rw-r--r--docs/users_guide/using.xml26
4 files changed, 43 insertions, 1 deletions
diff --git a/compiler/main/DynFlags.hs b/compiler/main/DynFlags.hs
index e5153ea33a..51abf36370 100644
--- a/compiler/main/DynFlags.hs
+++ b/compiler/main/DynFlags.hs
@@ -139,6 +139,7 @@ data DynFlag
| Opt_WarnIsError -- -Werror; makes warnings fatal
| Opt_WarnDuplicateExports
| Opt_WarnHiShadows
+ | Opt_WarnImplicitPrelude
| Opt_WarnIncompletePatterns
| Opt_WarnIncompletePatternsRecUpd
| Opt_WarnMissingFields
@@ -1024,6 +1025,7 @@ dynamic_flags = [
fFlags = [
( "warn-duplicate-exports", Opt_WarnDuplicateExports ),
( "warn-hi-shadowing", Opt_WarnHiShadows ),
+ ( "warn-implicit-prelude", Opt_WarnImplicitPrelude ),
( "warn-incomplete-patterns", Opt_WarnIncompletePatterns ),
( "warn-incomplete-record-updates", Opt_WarnIncompletePatternsRecUpd ),
( "warn-missing-fields", Opt_WarnMissingFields ),
diff --git a/compiler/rename/RnNames.lhs b/compiler/rename/RnNames.lhs
index 253d262fcf..4a880ed1fb 100644
--- a/compiler/rename/RnNames.lhs
+++ b/compiler/rename/RnNames.lhs
@@ -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)
@@ -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}
diff --git a/docs/users_guide/flags.xml b/docs/users_guide/flags.xml
index 48cf03ae73..8e185701c3 100644
--- a/docs/users_guide/flags.xml
+++ b/docs/users_guide/flags.xml
@@ -733,7 +733,7 @@
</row>
<row>
<entry><option>-Wall</option></entry>
- <entry>enable all warnings</entry>
+ <entry>enable almost all warnings (details in <xref linkend="options-sanity"/>)</entry>
<entry>dynamic</entry>
<entry><option>-w</option></entry>
</row>
@@ -766,6 +766,13 @@
<entry><option>-fno-warn-hi-shadowing</option></entry>
</row>
+ <row>
+ <entry><option>-fwarn-implicit-prelude</option></entry>
+ <entry>warn when the Prelude is implicitly imported</entry>
+ <entry>dynamic</entry>
+ <entry><option>-fno-warn-implicit-prelude</option></entry>
+ </row>
+
<row>
<entry><option>-fwarn-incomplete-patterns</option></entry>
<entry>warn when a pattern match could fail</entry>
diff --git a/docs/users_guide/using.xml b/docs/users_guide/using.xml
index 88c2c9ed6c..544a6e85d2 100644
--- a/docs/users_guide/using.xml
+++ b/docs/users_guide/using.xml
@@ -848,6 +848,7 @@ ghc -c Foo.hs</screen>
<listitem><option>-fwarn-tabs</option></listitem>
<listitem><option>-fwarn-incomplete-record-updates</option></listitem>
<listitem><option>-fwarn-monomorphism-restriction</option></listitem>
+ <listitem><option>-fwarn-implicit-prelude</option></listitem>
</itemizedlist>
</listitem>
</varlistentry>
@@ -914,6 +915,31 @@ ghc -c Foo.hs</screen>
</varlistentry>
<varlistentry>
+ <term><option>-fwarn-implicit-prelude</option>:</term>
+ <listitem>
+ <indexterm><primary><option>-fwarn-implicit-prelude</option></primary></indexterm>
+ <indexterm><primary>implicit prelude, warning</primary></indexterm>
+ <para>Have the compiler warn if the Prelude is implicitly
+ imported. This happens unless either the Prelude module is
+ explicitly imported with an <literal>import ... Prelude ...</literal>
+ line, or this implicit import is disabled (either by
+ <option>-fno-implicit-prelude</option> or a
+ <literal>LANGUAGE NoImplicitPrelude</literal> pragma).</para>
+
+ <para>Note that no warning is given for syntax that implicitly
+ refers to the Prelude, even if <option>-fno-implicit-prelude</option>
+ would change whether it refers to the Prelude.
+ For example, no warning is given when
+ <literal>368</literal> means
+ <literal>Prelude.fromInteger (368::Prelude.Integer)</literal>
+ (where <literal>Prelude</literal> refers to the actual Prelude module,
+ regardless of the imports of the module being compiled).</para>
+
+ <para>This warning is off by default.</para>
+ </listitem>
+ </varlistentry>
+
+ <varlistentry>
<term><option>-fwarn-incomplete-patterns</option>:</term>
<listitem>
<indexterm><primary><option>-fwarn-incomplete-patterns</option></primary></indexterm>