Commit fad822e2 authored by Tao He's avatar Tao He Committed by Ben Gamari

Improve the warning message of qualified unused imports.

Pretty-print unused imported names unqualified unconditionally to
make the warning message consistent for ambiguous/unambiguous
identifiers.
Signed-off-by: Tao He's avatarHE, Tao <sighingnow@gmail.com>

Test Plan: make test TEST="T14881"

Reviewers: bgamari, simonpj

Reviewed By: simonpj

Subscribers: simonpj, rwbarton, thomie, carter

GHC Trac Issues: #14881

Differential Revision: https://phabricator.haskell.org/D4461
parent 39c74063
......@@ -70,7 +70,7 @@ module Name (
NamedThing(..),
getSrcLoc, getSrcSpan, getOccString, getOccFS,
pprInfixName, pprPrefixName, pprModulePrefix,
pprInfixName, pprPrefixName, pprModulePrefix, pprNameUnqualified,
nameStableString,
-- Re-export the OccName stuff
......@@ -535,6 +535,10 @@ pprName (Name {n_sort = sort, n_uniq = uniq, n_occ = occ})
System -> pprSystem sty uniq occ
Internal -> pprInternal sty uniq occ
-- | Print the string of Name unqualifiedly directly.
pprNameUnqualified :: Name -> SDoc
pprNameUnqualified Name { n_occ = occ } = ppr_occ_name occ
pprExternal :: PprStyle -> Unique -> Module -> OccName -> Bool -> BuiltInSyntax -> SDoc
pprExternal sty uniq mod occ is_wired is_builtin
| codeStyle sty = ppr mod <> char '_' <> ppr_z_occ_name occ
......
......@@ -1401,9 +1401,12 @@ warnUnusedImport flag fld_env (L loc decl, used, unused)
pp_mod = ppr (unLoc (ideclName decl))
pp_not_used = text "is redundant"
-- In warning message, pretty-print identifiers unqualified unconditionally
-- to improve the consistent for ambiguous/unambiguous identifiers.
-- See trac#14881.
ppr_possible_field n = case lookupNameEnv fld_env n of
Just (fld, p) -> ppr p <> parens (ppr fld)
Nothing -> ppr n
Just (fld, p) -> pprNameUnqualified p <> parens (ppr fld)
Nothing -> pprNameUnqualified n
-- Print unused names in a deterministic (lexicographic) order
sort_unused = pprWithCommas ppr_possible_field $
......
module T14881 where
import qualified T14881Aux as Aux (L(Cons), x, tail, adjust, length)
x = Aux.Cons
[1 of 2] Compiling T14881Aux ( T14881Aux.hs, T14881Aux.o )
[2 of 2] Compiling T14881 ( T14881.hs, T14881.o )
T14881.hs:3:1: warning: [-Wunused-imports (in -Wextra)]
The qualified import of ‘adjust, length, L(tail), L(x)’
from module ‘T14881Aux’ is redundant
module T14881Aux where
-- unambiguous function name.
adjust :: ()
adjust = undefined
-- ambiguous function name.
length :: ()
length = undefined
data L = Cons { x :: Int -- unambiguous field selector
, tail :: [Int] -- ambiguous field selector
}
......@@ -153,3 +153,4 @@ test('T12548', normal, compile, [''])
test('T13132', normal, compile, [''])
test('T13646', normal, compile, [''])
test('LookupSub', [], multimod_compile, ['LookupSub', '-v0'])
test('T14881', [], multimod_compile, ['T14881', '-W'])
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment