From 536852b1348fde6ec0ba13859cc5ddf8480a1653 Mon Sep 17 00:00:00 2001 From: Isaac Dupree Date: Fri, 11 May 2007 08:45:25 +0000 Subject: [PATCH] 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. --- compiler/main/DynFlags.hs | 2 ++ compiler/rename/RnNames.lhs | 7 +++++++ docs/users_guide/flags.xml | 9 ++++++++- docs/users_guide/using.xml | 26 ++++++++++++++++++++++++++ 4 files changed, 43 insertions(+), 1 deletion(-) diff --git a/compiler/main/DynFlags.hs b/compiler/main/DynFlags.hs index e5153ea..51abf36 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 253d262..4a880ed 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 48cf03a..8e18570 100644 --- a/docs/users_guide/flags.xml +++ b/docs/users_guide/flags.xml @@ -733,7 +733,7 @@ - enable all warnings + enable almost all warnings (details in ) dynamic @@ -766,6 +766,13 @@ + + + warn when the Prelude is implicitly imported + dynamic + + + warn when a pattern match could fail diff --git a/docs/users_guide/using.xml b/docs/users_guide/using.xml index 88c2c9e..544a6e8 100644 --- a/docs/users_guide/using.xml +++ b/docs/users_guide/using.xml @@ -848,6 +848,7 @@ ghc -c Foo.hs + @@ -914,6 +915,31 @@ ghc -c Foo.hs + : + + + implicit prelude, warning + Have the compiler warn if the Prelude is implicitly + imported. This happens unless either the Prelude module is + explicitly imported with an import ... Prelude ... + line, or this implicit import is disabled (either by + or a + LANGUAGE NoImplicitPrelude pragma). + + Note that no warning is given for syntax that implicitly + refers to the Prelude, even if + would change whether it refers to the Prelude. + For example, no warning is given when + 368 means + Prelude.fromInteger (368::Prelude.Integer) + (where Prelude refers to the actual Prelude module, + regardless of the imports of the module being compiled). + + This warning is off by default. + + + + : -- 1.7.10.4