[commit: ghc] ghc-7.8: Fix over-zealous unused-import warning (a35a031)
git at git.haskell.org
git at git.haskell.org
Mon Jun 23 07:38:48 UTC 2014
Repository : ssh://git@git.haskell.org/ghc
On branch : ghc-7.8
Link : http://ghc.haskell.org/trac/ghc/changeset/a35a0315e3e928b4d9758c71e1a7ef8e034d16f9/ghc
>---------------------------------------------------------------
commit a35a0315e3e928b4d9758c71e1a7ef8e034d16f9
Author: Simon Peyton Jones <simonpj at microsoft.com>
Date: Fri May 2 12:09:52 2014 +0100
Fix over-zealous unused-import warning
See Note [Un-warnable import decls] in RnNames.
Fixes Trac #9061.
(cherry picked from commit 9f3e39d5f8686e511ffca406a6e056dec4095e53)
>---------------------------------------------------------------
a35a0315e3e928b4d9758c71e1a7ef8e034d16f9
compiler/rename/RnNames.lhs | 24 ++++++++++++++++++++----
testsuite/tests/module/T9061.hs | 6 ++++++
testsuite/tests/module/all.T | 1 +
3 files changed, 27 insertions(+), 4 deletions(-)
diff --git a/compiler/rename/RnNames.lhs b/compiler/rename/RnNames.lhs
index 56ee969..bddafe0 100644
--- a/compiler/rename/RnNames.lhs
+++ b/compiler/rename/RnNames.lhs
@@ -1285,7 +1285,7 @@ type ImportDeclUsage
warnUnusedImportDecls :: TcGblEnv -> RnM ()
warnUnusedImportDecls gbl_env
= do { uses <- readMutVar (tcg_used_rdrnames gbl_env)
- ; let imports = filter explicit_import (tcg_rn_imports gbl_env)
+ ; let imports = filterOut un_warnable_import (tcg_rn_imports gbl_env)
rdr_env = tcg_rdr_env gbl_env
; let usage :: [ImportDeclUsage]
@@ -1299,11 +1299,27 @@ warnUnusedImportDecls gbl_env
; whenGOptM Opt_D_dump_minimal_imports $
printMinimalImports usage }
where
- explicit_import (L _ decl) = not (ideclImplicit decl)
- -- Filter out the implicit Prelude import
- -- which we do not want to bleat about
+ un_warnable_import (L _ decl) -- See Note [Un-warnable import decls]
+ | ideclImplicit decl
+ = True
+ | Just (True, hides) <- ideclHiding decl
+ , not (null hides)
+ , pRELUDE_NAME == unLoc (ideclName decl)
+ = True
+ | otherwise
+ = False
\end{code}
+Note [Un-warnable import decls]
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+We do not warn about the implicit import of Prelude, since the user can't remove it
+
+We do not warn about
+ import Prelude hiding( x, y )
+because even if nothing else from Prelude is used, it may be essential to hide
+x,y to avoid name-shadowing warnings. Example (Trac #9061)
+ import Prelude hiding( log )
+ f x = log where log = ()
Note [The ImportMap]
~~~~~~~~~~~~~~~~~~~~
diff --git a/testsuite/tests/module/T9061.hs b/testsuite/tests/module/T9061.hs
new file mode 100644
index 0000000..1417dca
--- /dev/null
+++ b/testsuite/tests/module/T9061.hs
@@ -0,0 +1,6 @@
+{-# OPTIONS_GHC -fwarn-unused-imports #-}
+module T9061 where
+
+import Prelude hiding (log)
+
+f = log where log = ()
diff --git a/testsuite/tests/module/all.T b/testsuite/tests/module/all.T
index 8eaa1d5..926cbb5 100644
--- a/testsuite/tests/module/all.T
+++ b/testsuite/tests/module/all.T
@@ -334,3 +334,4 @@ test('T414', normal, compile_fail, [''])
test('T414a', normal, compile, [''])
test('T414b', normal, compile, [''])
test('T3776', normal, compile, [''])
+test('T9061', normal, compile, [''])
More information about the ghc-commits
mailing list