[commit: ghc] master: Fix over-zealous unused-import warning (9f3e39d)
git at git.haskell.org
git at git.haskell.org
Tue May 6 08:43:31 UTC 2014
Repository : ssh://git@git.haskell.org/ghc
On branch : master
Link : http://ghc.haskell.org/trac/ghc/changeset/9f3e39d5f8686e511ffca406a6e056dec4095e53/ghc
>---------------------------------------------------------------
commit 9f3e39d5f8686e511ffca406a6e056dec4095e53
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.
>---------------------------------------------------------------
9f3e39d5f8686e511ffca406a6e056dec4095e53
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 7f6a840..678eb73 100644
--- a/compiler/rename/RnNames.lhs
+++ b/compiler/rename/RnNames.lhs
@@ -1301,7 +1301,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]
@@ -1315,11 +1315,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