Ticket #5211 (closed bug: fixed)

Opened 2 years ago

Last modified 2 years ago

Missing warning about redundant import for a class instance

Reported by: Lemming Owned by:
Priority: normal Milestone:
Component: Compiler Version: 6.12.3
Keywords: Cc: ghc@…
Operating System: Unknown/Multiple Architecture: Unknown/Multiple
Type of failure: None/Unknown Difficulty:
Test Case: rename/should_fail/T5211 Blocked By:
Blocking: Related Tickets:

Description

I have the following module

module RedundantImport where

-- this import is redundant, but GHC does not spot it
import qualified Foreign.Storable as St

import Foreign.Storable (Storable, sizeOf, alignment, peek, poke, )
import Foreign.Ptr (castPtr, )


newtype T a = Cons a


instance Storable a => Storable (T a) where
   sizeOf (Cons a) = sizeOf a
   alignment (Cons a) = alignment a
   peek = fmap Cons . peek . castPtr
   poke p (Cons a) = poke (castPtr p) a

If loaded into GHCi with -Wall option, then GHCi does not give a warning, although the first import is redundant. It might have to do with the way how GHC accepts unqualified method names in instance implementations although the concerned method names are only imported in a qualified way.

Change History

Changed 2 years ago by simonpj

  • status changed from new to closed
  • testcase set to rename/should_fail/T5211
  • resolution set to fixed

Excellent point thank you! Fixed by

commit 6f60f1f541cafdb3bfdd71d48eb9dd7f0a708bda
Author: Simon Peyton Jones <simonpj@microsoft.com>
Date:   Sat Jun 11 14:19:44 2011 +0100

    Fix tracking of what RdrNames are used (fixes Trac #5211)
    
    The issue here was: what import declaration brings into
    scope the 'op here
    
       import qualified Foo( op )
       import Bar( C(op) )
       instance C Int where
         op = ...
    
    Well, the import of Bar, obviously.  But what if the
    import Bar had been
       import Bar( C )
    Then the instance is still supposed to work, getting
    op from the Foo.op imported from Foo.  (I'm assuming its
    the same op, of course.)

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

 compiler/basicTypes/RdrName.lhs |    2 +-
 compiler/ghci/Debugger.hs       |    1 -
 compiler/rename/RnEnv.lhs       |   35 ++++++++++++++++++++++++++---------
 3 files changed, 27 insertions(+), 11 deletions(-)

Simon

Note: See TracTickets for help on using tickets.