[GHC] #10890: Incorrect redundant import warning for type classes

GHC ghc-devs at haskell.org
Tue Oct 13 05:46:44 UTC 2015


#10890: Incorrect redundant import warning for type classes
-------------------------------------+-------------------------------------
        Reporter:  quchen            |                Owner:
            Type:  bug               |               Status:  patch
        Priority:  normal            |            Milestone:  8.0.1
       Component:  Compiler          |              Version:  7.10.2
      Resolution:                    |             Keywords:
Operating System:  Unknown/Multiple  |         Architecture:
                                     |  Unknown/Multiple
 Type of failure:  None/Unknown      |            Test Case:
      Blocked By:                    |             Blocking:
 Related Tickets:                    |  Differential Rev(s):  Phab:D1257
-------------------------------------+-------------------------------------

Comment (by Austin Seipp <austin@…>):

 In [changeset:"1818b48e420fd0f689105da76721895aadee7fd6/ghc" 1818b48/ghc]:
 {{{
 #!CommitTicketReference repository="ghc"
 revision="1818b48e420fd0f689105da76721895aadee7fd6"
 Fix incorrect import warnings when methods with identical names are
 imported

 Currently, GHC's warning generation code is assuming that a name
 (`RdrName`)
 can be imported at most once. This is a correct assumption, because 1)
 it's OK
 to import same names as long as we don't use any of them 2) when we use
 one of
 them, GHC generates an error because it doesn't disambiguate it
 automatically.

 But apparently the story is different with typeclass methods. If I import
 two
 methods with same names, it's OK to use them in typeclass instance
 declarations, because the context specifies which one to use. For example,
 this
 is OK (where modules A and B define typeclasses A and B, both with a
 function
 has),

     import A
     import B

     data Blah = Blah

     instance A Blah where
       has = Blah

     instance B Blah where
       has = Blah

 But GHC's warning generator is not taking this into account, and so if I
 change
 import list of this program to:

     import A (A (has))
     import B (B (has))

 GHC is printing these warnings:

     Main.hs:5:1: Warning:
         The import of ‘A.has’ from module ‘A’ is redundant

     Main.hs:6:1: Warning:
         The import of ‘B.has’ from module ‘B’ is redundant

 Why? Because warning generation code is _silently_ ignoring multiple
 symbols
 with same names.

 With this patch, GHC takes this into account. If there's only one name,
 then
 this patch reduces to the previous version, that is, it works exactly the
 same
 as current GHC (thanks goes to @quchen for realizing this).

 Reviewed By: austin

 Differential Revision: https://phabricator.haskell.org/D1257

 GHC Trac Issues: #10890
 }}}

--
Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/10890#comment:12>
GHC <http://www.haskell.org/ghc/>
The Glasgow Haskell Compiler


More information about the ghc-tickets mailing list