Ticket #5860 (closed feature request: fixed)

Opened 16 months ago

Last modified 15 months ago

Ambiguity between redundant imports

Reported by: elliottt Owned by:
Priority: normal Milestone:
Component: Compiler Version: 7.4.1
Keywords: module system Cc:
Operating System: Unknown/Multiple Architecture: Unknown/Multiple
Type of failure: None/Unknown Difficulty: Unknown
Test Case: Blocked By:
Blocking: Related Tickets:

Description

GHC reports this program:

module Test where

import Data.ByteString (ByteString)
import qualified Data.ByteString as S

test :: ByteString -> ByteString
test x = x

as having a redundant import of Data.ByteString:

$ ghc -c -Wall Test.hs
Test.hs:4:1:
    Warning: The import of `Data.ByteString' is redundant
               except perhaps to import instances from `Data.ByteString'
             To import instances alone, use: import Data.ByteString()

However, removing the restricted import of Data.ByteString will cause the program to fail to compile, as the type is no longer available. The real problem is with the qualified import of Data.ByteString as S that is never referenced in the program.

Would it be possible to change the message to distinguish between the qualified import an the restricted import, by more than the line number?

Attachments

0001-Distinguish-between-normal-and-qualified-unused-impo.patch Download (1.1 KB) - added by elliottt 15 months ago.
Add "qualified" to warning when appropriate

Change History

Changed 15 months ago by simonpj

  • status changed from new to closed
  • difficulty set to Unknown
  • resolution set to invalid

Looks ok to me. The error message points to line 4, and the import of Data.ByteString on that line is indeed redundant. I suppose we could say "The qualified import of ...", but I'm inclined to let this lie. Reopen if you disagree.

Changed 15 months ago by elliottt

Add "qualified" to warning when appropriate

Changed 15 months ago by elliottt

  • status changed from closed to new
  • resolution invalid deleted

I can live with things the way they are, but I've attached a patch just in case that changes your mind :)

Changed 15 months ago by simonpj

  • status changed from new to closed
  • resolution set to fixed

A patch is irresistable. I buy:

commit 68b59ceeeeb6fadecb7712e414c4bdb60e4e676e
Author: Trevor Elliott <trevor@galois.com>
Date:   Thu Feb 9 11:53:34 2012 -0800

    Distinguish between normal and qualified unused imports

>---------------------------------------------------------------

 compiler/rename/RnNames.lhs |    5 ++++-
 1 files changed, 4 insertions(+), 1 deletions(-)

diff --git a/compiler/rename/RnNames.lhs b/compiler/rename/RnNames.lhs index b3a3f83..b1a61db 100644
--- a/compiler/rename/RnNames.lhs
+++ b/compiler/rename/RnNames.lhs
@@ -1512,7 +1512,10 @@ warnUnusedImport (L loc decl, used, unused)
                                    <+> ptext (sLit "import") <+> pp_mod <> parens empty ]
     msg2 = sep [pp_herald <+> quotes (pprWithCommas ppr unused),
                     text "from module" <+> quotes pp_mod <+> pp_not_used]
-    pp_herald   = text "The import of"
+    pp_herald  = text "The" <+> pp_qual <+> text "import of"
+    pp_qual
+      | ideclQualified decl = text "qualified"
+      | otherwise           = empty
     pp_mod      = ppr (unLoc (ideclName decl))
     pp_not_used = text "is redundant"

Thanks. Simon

Note: See TracTickets for help on using tickets.