Add a -fwarn-dodgy-exports flag; fixes #1911
authorIan Lynagh <igloo@earth.li>
Sun, 19 Jul 2009 20:01:24 +0000 (20:01 +0000)
committerIan Lynagh <igloo@earth.li>
Sun, 19 Jul 2009 20:01:24 +0000 (20:01 +0000)
This is used to control warnings that were previously unconditional.

compiler/main/DynFlags.hs
compiler/rename/RnNames.lhs
docs/users_guide/using.xml

index fce8eac..20ac77e 100644 (file)
@@ -186,6 +186,7 @@ data DynFlag
    | Opt_WarnUnusedMatches
    | Opt_WarnWarningsDeprecations
    | Opt_WarnDeprecatedFlags
+   | Opt_WarnDodgyExports
    | Opt_WarnDodgyImports
    | Opt_WarnOrphans
    | Opt_WarnTabs
@@ -931,6 +932,7 @@ minusWOpts
         Opt_WarnUnusedMatches,
         Opt_WarnUnusedImports,
         Opt_WarnIncompletePatterns,
+        Opt_WarnDodgyExports,
         Opt_WarnDodgyImports
       ]
 
@@ -1652,6 +1654,7 @@ useInstead flag turn_on
 fFlags :: [(String, DynFlag, Bool -> Deprecated)]
 fFlags = [
   ( "warn-dodgy-foreign-imports",       Opt_WarnDodgyForeignImports, const Supported ),
+  ( "warn-dodgy-exports",               Opt_WarnDodgyExports, const Supported ),
   ( "warn-dodgy-imports",               Opt_WarnDodgyImports, const Supported ),
   ( "warn-duplicate-exports",           Opt_WarnDuplicateExports, const Supported ),
   ( "warn-hi-shadowing",                Opt_WarnHiShadows, const Supported ),
index 1052db6..63f29d9 100644 (file)
@@ -893,6 +893,7 @@ exports_from_avail (Just rdr_items) rdr_env imports this_mod
 
        | otherwise
        = do { implicit_prelude <- doptM Opt_ImplicitPrelude
+             ; warnDodgyExports <- doptM Opt_WarnDodgyExports
              ; let { exportValid = (mod `elem` imported_modules)
                             || (moduleName this_mod == mod)
                    ; gres = filter (isModuleExported implicit_prelude mod)
@@ -901,7 +902,7 @@ exports_from_avail (Just rdr_items) rdr_env imports this_mod
                    }
 
              ; checkErr exportValid (moduleNotImported mod)
-            ; warnIf (exportValid && null gres) (nullModuleExport mod)
+            ; warnIf (warnDodgyExports && exportValid && null gres) (nullModuleExport mod)
 
             ; addUsedRdrNames (concat [ [mkRdrQual mod occ, mkRdrUnqual occ]
                                        | occ <- map nameOccName names ])
@@ -955,12 +956,14 @@ exports_from_avail (Just rdr_items) rdr_env imports this_mod
                                 Nothing -> mkRdrUnqual
                                 Just (modName, _) -> mkRdrQual modName
              addUsedRdrNames $ map (mkKidRdrName . nameOccName) kids
-            when (null kids)
-                 (if (isTyConName name) then addWarn (dodgyExportWarn name)
-                               -- This occurs when you export T(..), but
-                               -- only import T abstractly, or T is a synonym.  
-                  else addErr (exportItemErr ie))
-                       
+             warnDodgyExports <- doptM Opt_WarnDodgyExports
+             when (null kids) $
+                  if isTyConName name
+                  then when warnDodgyExports $ addWarn (dodgyExportWarn name)
+                  else -- This occurs when you export T(..), but
+                       -- only import T abstractly, or T is a synonym.  
+                       addErr (exportItemErr ie)
+
              return (IEThingAll name, AvailTC name (name:kids))
 
     lookup_ie ie@(IEThingWith rdr sub_rdrs)
index f668639..06b9ccc 100644 (file)
@@ -860,6 +860,7 @@ ghc -c Foo.hs</screen>
          <indexterm><primary>-W option</primary></indexterm>
          <para>Provides the standard warnings plus
          <option>-fwarn-incomplete-patterns</option>,
+         <option>-fwarn-dodgy-exports</option>,
          <option>-fwarn-dodgy-imports</option>,
          <option>-fwarn-unused-matches</option>,
          <option>-fwarn-unused-imports</option>, and
@@ -991,6 +992,20 @@ foreign import "&amp;f" f :: FunPtr t
       </varlistentry>
 
       <varlistentry>
+       <term><option>-fwarn-dodgy-exports</option>:</term>
+       <listitem>
+         <indexterm><primary><option>-fwarn-dodgy-exports</option></primary>
+         </indexterm>
+         <para>Causes a warning to be emitted when a datatype
+      <literal>T</literal> is exported
+      with all constructors, i.e. <literal>T(..)</literal>, but is it
+      just a type synonym.</para>
+         <para>Also causes a warning to be emitted when a module is
+      re-exported, but that module exports nothing.</para>
+       </listitem>
+      </varlistentry>
+
+      <varlistentry>
        <term><option>-fwarn-dodgy-imports</option>:</term>
        <listitem>
          <indexterm><primary><option>-fwarn-dodgy-imports</option></primary>