Opened 9 years ago

Closed 8 years ago

#2267 closed bug (fixed)

Bogus "unused import" warning

Reported by: simonpj Owned by:
Priority: high Milestone: 6.12.1
Component: Compiler Version: 6.10.1
Keywords: Cc:
Operating System: Unknown/Multiple Architecture: Unknown/Multiple
Type of failure: None/Unknown Test Case:
Blocked By: Blocking:
Related Tickets: Differential Rev(s):
Wiki Page:

Description

In DsMeta (in the source code for GHC itself), there's an import

  import qualified OccName

With -fwarn-unused-imports we get the warning

deSugar/DsMeta.hs:45:0:
    Warning: Module `OccName' is imported, but nothing from it is used,
               except perhaps instances visible in `OccName'
             To suppress this warning, use: import OccName()

But that's wrong: there are several uses of things imported from OccName.

I tried to reproduce this in a much smaller program, and failed, so something not entirely trivial is happening. Hence this ticket, to make sure we don't forget.

Change History (10)

comment:1 Changed 9 years ago by igloo

I haven't checked, but I assume it's another example of #1074.

comment:2 Changed 9 years ago by simonmar

Architecture: UnknownUnknown/Multiple

comment:3 Changed 9 years ago by simonmar

Operating System: UnknownUnknown/Multiple

comment:4 Changed 9 years ago by igloo

Milestone: 6.10 branch6.10.2
Priority: normalhigh

comment:5 Changed 9 years ago by snoyberg

Version: 6.8.26.10.1

Here's a small program with the bug. Hope this helps.

{-# OPTIONS_GHC -fwarn-unused-imports -Werror #-}
import qualified Data.ByteString as B
import qualified Data.ByteString.UTF8 as BU

toString :: B.ByteString -> String
toString = BU.toString

fromString :: String -> B.ByteString
fromString = BU.fromString

main :: IO ()
main = putStrLn $ toString $ fromString "Hello World!"

comment:6 Changed 9 years ago by simonpj

See also #2995

comment:7 Changed 9 years ago by igloo

Milestone: 6.10.26.10 branch

comment:8 Changed 9 years ago by seliopou

The problem is that the GlobalRdrElt for B.ByteString has two ImportSpecs for its Provenance, only the first of which (the "wrong" one, i.e., Data.ByteString.UTF8) is being added to minimal_imports1, which is then used to construct unused_imp_mods in reportUnusedNames (rename/RnNames.lhs:1084).

comment:9 Changed 9 years ago by igloo

Milestone: 6.10 branch6.12.1

comment:10 Changed 8 years ago by igloo

Resolution: fixed
Status: newclosed

Fixed by:

Mon Jul  6 12:25:03 BST 2009  simonpj@microsoft.com
  * Major patch to fix reporting of unused imports
Note: See TracTickets for help on using tickets.