summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSimon Peyton Jones <simonpj@microsoft.com>2014-05-02 12:09:52 +0100
committerSimon Peyton Jones <simonpj@microsoft.com>2014-05-05 09:12:15 +0100
commit9f3e39d5f8686e511ffca406a6e056dec4095e53 (patch)
tree6f8330a048ed9352f049ef8be341d83f1902630f
parentf0fcc41d755876a1b02d1c7c79f57515059f6417 (diff)
downloadhaskell-9f3e39d5f8686e511ffca406a6e056dec4095e53.tar.gz
Fix over-zealous unused-import warning
See Note [Un-warnable import decls] in RnNames. Fixes Trac #9061.
-rw-r--r--compiler/rename/RnNames.lhs24
-rw-r--r--testsuite/tests/module/T9061.hs6
-rw-r--r--testsuite/tests/module/all.T1
3 files changed, 27 insertions, 4 deletions
diff --git a/compiler/rename/RnNames.lhs b/compiler/rename/RnNames.lhs
index 7f6a840295..678eb73395 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 0000000000..1417dcad75
--- /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 8eaa1d5217..926cbb5448 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, [''])